使用pecl安装Php PDO OCI驱动程序

时间:2015-06-02 22:59:57

标签: php pdo oci

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

在Google上搜索pdo_oci时,我找到以下网址:

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

2 个答案:

答案 0 :(得分:6)

修改

如果您已经安装了php(例如来自存储库),则只能从PHP源代码编译PDO_OCI(您需要安装Instantclient)

  • Download the PHP source与您拥有的版本相同 安装;
  • 解压缩;
  • 转到目录 的 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

此方法只会在PHP extensions文件夹中创建一个pdo_oci.so,不需要重新编译整个PHP。您可以使用PHP的存储库版本来执行此操作,并且可以使用PHP源中 ext 文件夹中的任何扩展来执行此操作。

首先,抱歉我的英语不好。

我有同样的问题,但我已经可以解决了。

正如消息所述,此PECL扩展已弃用。您需要使用PHP Source中包含的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

答案 1 :(得分:1)

安装Oracle驱动程序后,您可以使用此this class here然后只需更改PDO连接

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

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

其余部分的工作方式与使用PDO对象完全相同。