博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
phalcon: 解决php7/phalcon3.2以上版本,不支持oracle数据库的方法
阅读量:6943 次
发布时间:2019-06-27

本文共 3887 字,大约阅读时间需要 12 分钟。

解决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 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;  		}  	    }  	});

  

转载地址:http://iiinl.baihongyu.com/

你可能感兴趣的文章
[笔记]shell中算术扩展基础
查看>>
python 之中文全攻略
查看>>
MDT2012部署问题,Litetouch.wfs和Litetouch.vbs的区别
查看>>
__init__.py 作用详解
查看>>
puppet安装使用教程(四)--puppet的工作原理及工作过程
查看>>
mysql查询今天、昨天、上周
查看>>
【Composer】实战操作二:自己创建composer包并提交
查看>>
linux 安装
查看>>
基于Redis的作业执行设计总结
查看>>
php添加mysqli扩展
查看>>
右下角弹窗,CSS
查看>>
linux基础入门命令---whereis、whatis、which命令
查看>>
linux添加用户切换后显示-bash4.1$的解决办法
查看>>
JVM调优总结 -Xms -Xmx -Xmn -Xss
查看>>
JSP自定义标签
查看>>
Shell脚本学习三:生成随机数
查看>>
singleTop和singleTask有什么区别?(活动 Activity 四种加载模式)
查看>>
【腾讯Bugly干货分享】QFix探索之路—手Q热补丁轻量级方案
查看>>
iOS学习之移除Main.storyboard
查看>>
感人至深的老情书
查看>>