解決php7/phalcon3.2以上版本,不支持oracle數據庫的方法php
phalcon3.2(3.0以上)版本不支持oracle的方法。html
https://github.com/phalcon/incubatorgit
參考以上路徑的方法:github
個人phalcon是3.2.4web
1.在項目路徑根目錄下,個人:數據庫
在根目錄下,新建:composer.json,json
個人phalcon是3.2.4,那麼對應的版本是3.2php7
{ "require": { "phalcon/incubator": "^3.2" } }
2.而後執行安裝oracle
curl -s http://getcomposer.org/installer | php
3.安裝:app
php composer.phar install
4.在根木目錄下,新建一個文件,來驗證:
$loader = new Phalcon\Loader(); $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 Phalcon\Db\Adapter\Pdo\Oracle(array( 'adapter' => "{$adapter}", 'username' => "{$username}", 'password' => "{$password}", 'dbname' => "//{$host}:{$port}/{$service_name}", 'charset' => "{$charset}" )); $data = $db->fetchAll( " SELECT * FROM WX_USER WHERE rownum<10", Phalcon\Db::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