解决php7/phalcon3.2以上版本,不支持oracle数据库的方法
phalcon3.2(3.0以上)版本不支持oracle的方法。
https://github.com/phalcon/incubator
参考以上路径的方法:
我的phalcon是3.2.4
1.在项目路径根目录下,我的:
在根目录下,新建:composer.json,
我的phalcon是3.2.4,那么对应的版本是3.2
{ "require": { "phalcon/incubator": "^3.2" } }
2.然后执行安装
curl -s http://getcomposer.org/installer | php
3.安装:
php composer.phar install
4.在根木目录下,新建一个文件,来验证:
$loader = new PhalconLoader(); $loader->registerNamespaces([ 'Phalcon' => '/var/www/html/wxsdairpro/vendor/phalcon/incubator/Library/Phalcon/' ]); $loader->register(); $database=array( 'adapter' => 'Oracle', 'host' => 'xxxxx', 'username' => 'xxxxx', 'password' => 'xxxxx', 'port' => '1521', 'charset' => 'AL32UTF8', 'service_name' => 'wweborc' ); extract($database); // vendor 自动加载 spl_autoload_register(function ($class) { if ($class) { $file = str_replace('\', '/', $class); $file .= '.php'; if (!file_exists($file)) { $classParts = explode("/", $file); $rebuildClass = ''; foreach ($classParts as $part) { $part = ucfirst($part); $rebuildClass .= $part . "/"; } $rebuildClass = rtrim($rebuildClass, "/"); $file = 'vendor/phalcon/incubator/Library/' . $rebuildClass; //$file = "vendor/phalcon/incubator/Library/Phalcon/Db/Dialect/Oracle.php"; include_once $file; } } }); $db = new PhalconDbAdapterPdoOracle(array( 'adapter' => "{$adapter}", 'username' => "{$username}", 'password' => "{$password}", 'dbname' => "//{$host}:{$port}/{$service_name}", 'charset' => "{$charset}" )); $data = $db->fetchAll( " SELECT * FROM WX_USER WHERE rownum<10", PhalconDb::FETCH_ASSOC); var_dump($data);
这里需要说一下,这里的包文件,涉及到oracle的类,命名空间,有大小写bug,所以需要转换一下:
//记住这里,因为这个包中的oracle命名的大小写根phalcon中的oracle大小写有出入,所以需要转换一下
spl_autoload_register(function ($class) { if ($class) { $file = str_replace('\', '/', $class); $file .= '.php'; if (!file_exists($file)) { $classParts = explode("/", $file); $rebuildClass = ''; foreach ($classParts as $part) { //记住这里,因为这个包中的oracle命名的大小写根phalcon中的oracle大小写有出入,所以需要转换一下 $part = ucfirst($part); $rebuildClass .= $part . "/"; } $rebuildClass = rtrim($rebuildClass, "/"); $file = 'vendor/phalcon/incubator/Library/' . $rebuildClass; //$file = "vendor/phalcon/incubator/Library/Phalcon/Db/Dialect/Oracle.php"; include_once $file; } } });
//记住这里,因为这个包中的oracle命名的大小写根phalcon中的oracle大小写有出入,所以需要转换一下
在入口文件处,修改一下:
$loader = new Loader(); $loader->registerDirs( array( __DIR__ . $config->application->ticketDir, __DIR__ . $config->application->wxpayDir, __DIR__ . $config->application->controllersDir, __DIR__ . $config->application->logicDir, __DIR__ . $config->application->modelsDir, __DIR__ . $config->application->pluginsDir, __DIR__ . $config->application->utilDir, ) ); // important $loader->registerNamespaces([ 'Phalcon' => __DIR__ .'/../vendor/phalcon/incubator/Library/Phalcon/' ]); $loader->register();
// Create a DI $di = new FactoryDefault(); // Setup a base URI so that all generated URIs include the "tutorial" folder $di['url'] = function() { $url = new Url(); $url->setBaseUri('/'); return $url; }; // phalcon 3rd library vendor 自动加载 spl_autoload_register(function ($class) { if ($class) { $file = str_replace('\', '/', $class); $file .= '.php'; if (!file_exists($file)) { $classParts = explode("/", $file); $rebuildClass = ''; foreach ($classParts as $part) { $part = ucfirst($part); $rebuildClass .= $part . "/"; } $rebuildClass = rtrim($rebuildClass, "/"); $file = __DIR__ . '/../vendor/phalcon/incubator/Library/' . $rebuildClass; include_once $file; } } });
下载地址:https://download.csdn.net/download/gzyftk/11472630