oracle 启用 PDO OCI
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21229821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enabling PDO OCI
提问by Warej
I've tried to install OCI, so I can use new PDO("oci:dbname...
我已经尝试安装 OCI,所以我可以使用 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).
经过 1,5 小时的战斗,我安装了 oracle Instantclient(基本和 sdk),然后安装了 oci for php(如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.
现在我有点困惑,因为我的 PHPinfo 告诉我启用了 OCI8 支持,但是在 PDO 部分中,“PDO 驱动程序”部分中只有 odbc。
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
PS 我已经安装了 XUBUNTU 12.10 和以下数据包: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
编辑:感谢您的解释。现在我正在尝试安装“pdo_oci”,如下所示: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
/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
配置:错误:在 /opt/oracle/instantclient 下找不到 Oracle-OCI 所需的库
I wonder if doing this on Windows wouldn't be easier.
我想知道在 Windows 上这样做会不会更容易。
回答by álvaro González
You should note that there're two completely different PHP extensions designed to connect to Oracle databases:
您应该注意到,有两个完全不同的 PHP 扩展旨在连接到 Oracle 数据库:
OCI8is the extension developed by Oracle Corporation. It's actively maintained and it's the recommended way to interact with Oracle.
PDO_OCIis the PDO driver developed by the community. It was never finished and it's actually kind of abandoned (thus the EXPERIMENTALwarning displayed in the documentation).
OCI8是 Oracle Corporation 开发的扩展。它得到积极维护,是与 Oracle 交互的推荐方式。
PDO_OCI是社区开发的 PDO 驱动程序。它从未完成,实际上有点被放弃了(因此在文档中显示了实验警告)。
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.
两者都包含OCI
(Oracle 调用接口)术语,因为两者都在内部使用 Oracle 提供的 OCI API。因此,无论您选择什么库,都需要 Oracle Instant Client。但是你需要安装相应的PHP包。
In your case, you're installing OCI8 and then trying to run PDO code.
就您而言,您正在安装 OCI8,然后尝试运行 PDO 代码。
回答by taq
If you're having trouble getting the php_pdo_oci library installed either via pecl or via compiling from source, this pdooci class on githubmay be able to help. The only difference is the way you instantiate your pdo object. Change from:
如果您在通过 pecl 或从源代码编译安装 php_pdo_oci 库时遇到问题,github 上的这个 pdooci 类可能会有所帮助。唯一的区别是实例化 pdo 对象的方式。更改自:
$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.
其余部分的工作方式与您使用 PDO 对象时完全相同。
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.
您仍然需要安装 php_oci8 扩展,但由于此扩展是积极维护的,并且通常是操作系统存储库的一部分,因此安装应该没有问题。