Enabling PDO OCI

╄→尐↘猪︶ㄣ 提交于 2019-12-24 04:22:07

问题


I've tried to install OCI, so I can use new PDO("oci:dbname...

After 1,5h of fight I've installed oracle instantclient (basic and sdk) and then oci for php (as described here http://ubuntuforums.org/showthread.php?t=92528).

Now I'm a bit confused because my PHPinfo tells that OCI8 Support is enabled, but in PDO section there's only odbc in "PDO drivers" section.

When did I go wrong?

P.S. I've got XUBUNTU 12.10 and following packets installed: php-pear, php5, php5-cli, php5-common, php5-dbg, php5-dev, php5-odbc

Edit: Thanks for explaining. Now I'm trying to install "pdo_oci" following this: http://lacot.org/blog/2009/11/03/ubuntu-php5-oci8-and-pdo_oci-the-perfect-install.html

and now invoking this:

/usr/local/src/PDO_OCI-1.0# ./configure --with-oci8=instantclient,/opt/oracle/instantclient,12.1

I'm getting following error:

configure: error: Oracle-OCI needed libraries not found under /opt/oracle/instantclient

I wonder if doing this on Windows wouldn't be easier.


回答1:


You should note that there're two completely different PHP extensions designed to connect to Oracle databases:

  • OCI8 is the extension developed by Oracle Corporation. It's actively maintained and it's the recommended way to interact with Oracle.

  • PDO_OCI is the PDO driver developed by the community. It was never finished and it's actually kind of abandoned (thus the EXPERIMENTAL warning displayed in the documentation).

Both contain the OCI (Oracle Call Interface) term because both make use internally of the OCI API provided by Oracle. As such, you need the Oracle Instant Client no matter what library you choose. But you then need to install the corresponding PHP packages.

In your case, you're installing OCI8 and then trying to run PDO code.




回答2:


If you're having trouble getting the php_pdo_oci library installed either via pecl or via compiling from source, this pdooci class on github may be able to help. The only difference is the way you instantiate your pdo object. Change from:

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

to:

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

The rest should work exactly the same as if you were using a PDO object.

You still need the php_oci8 extension installed but as this extension is actively maintained and normally part of OS repositories, it shouldn't be a problem to install.



来源:https://stackoverflow.com/questions/21229821/enabling-pdo-oci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!