Php PDO OCI驱动安装使用pecl


Php PDO OCI Driver installation using pecl

我正在尝试为OCI安装PDO驱动程序。

当搜索谷歌pdo_oci我发现以下URL:

https://pecl.php.net/package/PDO_OCI

在页面顶部显示以下信息:

该包已被替换,不再维护。包已移动到http://www.php.net/pdo_oci通道,包ext/pdo_oci.

这个消息是什么意思,我如何使用pecl添加这个通道?

我试图使用pear channel-discover php.net/pdo_oci添加该通道,但它似乎不起作用。我也找不到php.net/pdo_oci的channel.xml文件,所以我可以尝试pear channel-add channel.xml

EDIT

如果您已经安装了php(例如从存储库),您可以只从php源编译PDO_OCI(您需要安装instantclient)

  • 下载与您拥有的相同版本的PHP源代码安装;
  • 解压;
  • 更改到目录 php-YOUR-VERSION/ext/pdo_oci

在pdo_oci文件夹中,运行以下命令:

$ phpize  
$ ./configure --with-pdo-oci=instantclient,/usr,12.1  
$ make && make install  
$ echo "extension=pdo_oci.so" > /etc/php.d/pdo_oci.ini  
$ service httpd restart

这个方法只会创建一个pdo_oci。所以在PHP扩展文件夹中,不需要重新编译整个PHP。您可以使用存储库版本的PHP,也可以使用PHP源代码中ext文件夹中的任何扩展名。


首先,为我糟糕的英语道歉。

我也有同样的问题,但我已经能解决了。

正如消息所说,此PECL扩展已弃用。您需要使用PHP源代码中包含的PDO_OCI从源代码编译PHP。

我在CentOS 6.6中这样做,MySQL, Apache和InstantClient安装:

安装依赖项

curl-devel
freetype-devel
libc-client
libc-client-devel
libjpeg-devel
libmcrypt-devel
libpng-devel
libtool-ltdl-devel
libxml2-devel
libXpm-devel
libc-client
libc-client-devel
libmcrypt-devel
libpng-devel
db4-devel
...And other prompted dependencies in the ./configure 
(always install the *-devel package too)

下载PHP源码

$ wget http://ar2.php.net/get/php-5.6.10.tar.gz/from/this/mirror  

将下载的文件解压到文件夹

$ tar -xzf php-5.6.10.tar.gz  
$ cd php-5.6.10  

使用所需的参数执行configure命令(下面是我的示例)

./configure '   
--prefix=/usr '  
--sysconfdir=/etc '  
--localstatedir=/var '  
--datadir=/usr/share/php '  
--mandir=/usr/share/man '  
--with-config-file-path=/etc '  
--with-config-file-scan-dir=/etc/php.d '  
--with-zlib '  
--enable-bcmath '  
--with-bz2 '  
--enable-calendar '  
--with-gdbm '  
--with-gmp '  
--enable-ftp '  
--with-gettext '  
--enable-mbstring '  
--with-readline '  
--with-apxs2 '  
--with-pdo-oci=instantclient,/usr,12.1 '  
--enable-dba=shared '  
--with-pdo-mysql --with-mysql-sock=/var/mysql/mysql.sock '  
--with-pdo-pgsql ' 
--with-mcrypt '  
--with-mhash '  
--with-curl '  
--with-gd '
--enable-gd-native-ttf '
--with-jpeg-dir=/usr '
--with-png-dir=/usr '
--with-zlib-dir=/usr '
--with-xpm-dir=/usr '
--with-vpx-dir=/usr '
--with-freetype-dir=/usr '
--with-t1lib=/usr '
--with-libxml-dir=/usr '
--with-mysql=mysqlnd '
--with-mysqli=mysqlnd '  
--enable-soap '
--with-xmlrpc '
--with-xsl '
--with-tidy=/usr '
--enable-pcntl '
--enable-sysvshm '
--enable-sysvmsg '
--enable-shmop

如果你在运行这个命令时看到任何错误,你可能错过了一些依赖项(可能是我没有提到的依赖项)。

configure命令运行错误后

$ make && make install  

此时,PHP已经安装。要进行认证,请使用以下命令:

$ php -v  

但在结束之前,我们需要做一些调整…

复制php.ini到正确的目录

### If you're on a development server    
$ cp php.ini-development /etc/php.ini
### If you're on a production server
$ cp php.ini-production /etc/php.ini

打开Apache配置文件编辑

$ vi /etc/httpd/conf/httpd.conf

添加以下行以便Apache解释PHP(如果已经有则忽略)

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps   

重启Apache

$ service httpd restart

安装Oracle驱动程序后,您可以在这里使用这个类,然后您只需要更改PDO连接,例如

$pdo = new PDO("oci:dbname=mydatabase;charset=utf8", "user", "password");

$pdo = new PDOOCI'PDO("mydatabase", "user", "password");

其余部分应该与使用PDO对象完全相同。