PHP+Oracle本地开发环境搭建方法详解

yipeiwu_com7年前PHP代码库

安装instant client

首先,是从https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html下载相应的数据库版本对应的basic和devel的rpm包或zip压缩包。我这里选择rpm包。然后安装:

rpm -Uvh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

rpm -Uvh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

这样,instant client工具已经安装好了。接下来是PHP的扩展oci8。

安装oci8扩展

关于oci8的安装方法,在PHP官方文档中有详细的介绍,在线地址http://php.net/manual/en/oci8.installation.php。我这里选用pecl安装。直接运行命令:

pecl install oci8

注意,如果你和我一样使用的也是PHP7.0以上的版本,那么使用上面的命令。如果是其他版本,可以看到pecl的oci8页面有相关说明:

Use 'pecl install oci8-2.0.12' to install

for PHP 5.2 - PHP 5.6. Use 'pecl install oci8-1.4.10' to install for

PHP 4.3.9 - PHP 5.1

在运行安装命令后,会提示输入instant client路径,原文提示为:

Please provide the path to the ORACLE_HOME directory.

Use 'instantclient,/path/to/instant/client/lib' if you're compiling

with Oracle Instant Client [autodetect] :

默认路径为/usr/lib/oracle/11.2/client64/lib。注意,要在前面加上instantclient,完整输入为:

instantclient,/usr/lib/oracle/11.2/client64/lib

我第一次安装的时候,没有仔细阅读,只看到最后的autodetect便直接回车了,导致后面测试连接数据库失败。等待安装好后,还需要最后一步,便是在php.ini中加入配置extension=oci8.so或另起一个.ini文件,重启php-fpm

service php-fpm restart

现在,你便可以连接Oracle数据库了,本地开发环境也搭建好了。

相关文章

php function用法如何递归及return和echo区别

复制代码 代码如下: <?php //模拟sql数据 $array = array(0=>'apple',1=>'banana',2=>'cat',3=>'...

php实现的Curl封装类Curl.class.php用法实例分析

本文实例讲述了php实现的Curl封装类Curl.class.php用法。分享给大家供大家参考。具体如下: <?php //curl类 class Curl { fu...

php数组函数序列之array_intersect() 返回两个或多个数组的交集数组

array_intersect() 定义和用法 array_intersect() 函数返回两个或多个数组的交集数组。 结果数组包含了所有在被比较数组中,也同时出现在所有其他参数数组中的...

浅析PHP类的反射来实现依赖注入过程

PHP具有完整的反射 API,提供了对类、接口、函数、方法和扩展进行逆向工程的能力。通过类的反射提供的能力我们能够知道类是如何被定义的,它有什么属性、什么方法、方法都有哪些参数,类文件的...

PHP+JS+rsa数据加密传输实现代码

JS端代码: 复制代码 代码如下: //文件base64.js: var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...