“尝试使用PDO和OCI8扩展时出现"找不到驱动程序"”

huangapple go评论66阅读模式
英文:

"could not find driver" when trying to use PDO and OCI8 extension

问题

我认为我(不知怎么)已经正确安装了Oracle Instant Client。我似乎还正确添加了OCI8扩展到PHP 8.1。

OCI8是通过pecl install --configureoptions 'with-oci8="instantclient,/opt/oracle/instantclient"' oci8添加的。Oracle Instant Client是从zip文件安装的,sqlplus按预期工作。

如果我调用oci_connect(),会返回一个“oci8连接”资源。所以OCI8扩展似乎已经安装并且正常工作。

问题是,我正试图让Drupal数据库抽象与Oracle一起工作(用于迁移)。Drupal 9.5。我正在使用drupal/oracle的2.x-dev@dev分支。一切看起来都还好,直到Connection类到达$pdo = new \PDO(...);

PDO引发了一个带有“找不到驱动程序”的PDOException。对我来说不清楚PHP 8.1是否需要安装pdo_oci,或者它是否已经是PHP 8的一部分?

我如何告诉PHP安装/启用pdo_oci?稍微复杂一点,因为我试图让它在ddev容器中工作,而PHP是通过apt安装的。

英文:

I think I (magically) have Oracle Instant Client correctly installed. I also appear to have the OCI8 extension correctly added to PHP 8.1.

OCI8 was added with pecl install --configureoptions 'with-oci8="instantclient,/opt/oracle/instantclient"' oci8. Oracle Instant Client was installed from zip files and sqlplus works as expected.

If I call oci_connect(), I get an "oci8 connection" resource returned. So the OCI8 extension appears to be installed and working.

The problem is, I am trying to get Drupal database abstraction to work with Oracle (for migration). Drupal 9.5. I'm using the 2.x-dev@dev branch of drupal/oracle. All seems okay, until the Connection class arrives at $pdo = new \PDO(...);

PDO is throwing a PDOException with "could not find driver" as the message. It is unclear to me if PHP 8.1 requires pdo_oci to be installed or if it's already part of PHP 8?

How do I tell PHP to install/enable pdo_oci? Slightly more complicated because I'm trying to get this to work in a ddev container and PHP is being installed by apt.

答案1

得分: 1

我想我弄清楚了。可能欠社区一个更详细的解释,但现在我在Dockerfile(.ddev/web-build/Dockerfile)的RUN命令中添加了以下脚本。

#!/bin/bash

cd /tmp
wget https://www.php.net/distributions/php-8.1.16.tar.gz
tar -xvf  php-8.1.16.tar.gz
cd php-8.1.16/ext/pdo_oci/
phpize
./configure --with-pdo-oci=instantclient,/opt/oracle/instantclient
make && make install
rm -rf /tmp/php-8.1.16*
英文:

I think I sorted it out. Probably owe the community a more detailed explanation, but for now I added the following script in a RUN command in the Dockerfile (.ddev/web-build/Dockerfile)

#!/bin/bash

cd /tmp
wget https://www.php.net/distributions/php-8.1.16.tar.gz
tar -xvf  php-8.1.16.tar.gz
cd php-8.1.16/ext/pdo_oci/
phpize
./configure --with-pdo-oci=instantclient,/opt/oracle/instantclient
make && make install
rm -rf /tmp/php-8.1.16*

huangapple
  • 本文由 发表于 2023年3月15日 20:42:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定