【问题标题】:Php PDO OCI Driver installation using pecl使用 pecl 安装 Php PDO OCI 驱动程序
【发布时间】:2015-06-02 22:59:56
【问题描述】:

我正在尝试为 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

【问题讨论】:

  • 有几个选项;为了提供有用的答案,最好了解有关您的 PHP 安装的更多详细信息。您是使用预制包(例如在 debian 上,apt-get install php5…),还是自己编译 PHP?
  • 将 RHEL6 与 Remi 存储库一起使用。 2.6.32-504.3.3.el6.x86_64 #1 SMP Fri Dec 12 16:05:43 EST 2014 x86_64

标签: php pdo oracle-call-interface


【解决方案1】:

编辑

如果您已经安装了 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扩展文件夹中创建一个pdo_oci.so,不需要重新编译整个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

如果您在运行此命令时看到任何错误,则可能是缺少某些依赖项(可能是我没有提到的依赖项)。

运行配置命令后没有错误

$ 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

【讨论】:

  • 已编辑以包含更多详细信息
  • 谢谢你,对我有用(只是第一个,在第一个分隔符之前)
  • 在某些发行版上可能存在导致配置时Cannot find php_pdo_driver.h 的错误。 (bugs.php.net/bug.php?id=59450) 临时解决方法:在配置之前创建符号链接:sudo ln -s /usr/include/php5/ /usr/include/php
  • 非常感谢您拯救了我的一天!使用 php7.2-fpm 在 Ubuntu 18.10 上工作 :)
【解决方案2】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-16
    • 1970-01-01
    • 2013-06-17
    • 1970-01-01
    • 2016-02-02
    相关资源
    最近更新 更多