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

663 Views Asked by At

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

There are 1 best solutions below

1
JonMcL On

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*