I host a Drupal 9 website on shared hosting with CentOS, Apache, MariaDB 10.3, Mysqli support enabled and PHP 8.1.

I first installed this website with the command composer create-project drupal/recommended-project.

I ran the following commands to upgrade the Drupal 9 core to Drupal 10:

cd example.com
composer update
chmod 777 web/sites/default
chmod 666 web/sites/default/*settings.php
chmod 666 web/sites/default/*services.yml
composer require 'drupal/core-recommended:^10' 'drupal/core-composer-scaffold:^10' 'drupal/core-project-message:^10' --update-with-dependencies --no-update
composer update
vendor/bin/drush updatedb

I then got:

Error: Undefined constant PDO::MYSQL_ATTR_USE_BUFFERED_QUERY in Drupal\mysql\Driver\Database\mysql\Connection::open() (line 148 of /home/example.com/web/core/modules/mysql/src/Driver/Database/mysql/Connection.php).

Why do I get this error and what can be done against that?

Comments

dieterholvoet’s picture

This problem is not similar to this issue

as you suggested in your e-mail to me. It seems like that error occurs if something is wrong with your PHP installation, more specifically the pdo/pdo_mysql extensions not being installed.

Some references:

I suggest you check your shared hosting settings and contact them if you can't figure it out.

Does this error also happen if you enable and visit update.php through the browser? If not, this will probably be an issue with the CLI PHP installation, not with PHP-FPM. Make sure the right PHP executable is used when running vendor/bin/drush updatedb.

bendqh1’s picture

Indeed example.com/update.php worked.

I tend to think that this is indeed a PHP extension problem. Sadly in this shared server I have very little control about which such extensions are installed.

dieterholvoet’s picture

You can find which PHP installation FPM is using by visiting /admin/reports/status/php and looking for 'Configuration File (php.ini) Path'. For the CLI you can use php -i | grep "Configuration File (php.ini) Path". If those paths are different you can try to use the FPM PHP installation in your CLI by including the path to the right php binary in the PATH variable before running Drush, like this:

PATH="/RunCloud/Packages/php81rc/bin:$PATH"
vendor/bin/drush updb

Changing "/RunCloud/Packages/php81rc/bin" to the path of the PHP installation FPM uses, or just the path to an installation using the right PHP version and including the necessary PHP modules.

bendqh1’s picture

I am not a PHP programmer. Some terms here are foreign for me (FPM).

This is what I have found in the phpinfo() file:

Configuration File (php.ini) Path /opt/alt/php81/etc
Loaded Configuration File /opt/alt/php81/etc/php.ini
Scan this dir for additional .ini files /home/example/.system-php/ini/8.1/example.example.com
Additional .ini files parsed /home/example/.system-php/ini/8.1/example.example.com/php.ini

I hope it helps helping me.

bendqh1’s picture

This problem now happens in all Drupal websites I have.

The server PHP version is 8.1 and pdo and pdo_mysql are both installed.

I have created a new thread here:

https://www.drupal.org/forum/support/post-installation/2023-01-03/sudden...

bendqh1’s picture

diamondsea’s picture

I was able to fix this on my new Ubuntu install with by installing the php-mysql package:

sudo apt install php-mysql

sudo service apache2 restart

owenkaji’s picture

fIX in debian 

nathan tsai’s picture

The issue occurred when I updated to PHP 8.1.

I needed to make sure I had the php-pdo and the php-mysqlnd extensions installed.

albin.sopaj’s picture

How did you install those two extensions (php-pdo and php-mysqlnd)? And in what path?

diamondsea’s picture

Using an account that has `sudo` permissions (can run commands as the `root` user), run the appropriate one of these for your operating system.  The apt/yum commands will automatically install the code into the proper locations.

# For Ubuntu / Debian style Linux version
sudo apt install php-pdo php-mysqlnd

# For RedHat / Centos / Amazon Linux style Linux versions
sudo yum install php-pdo php-mysqlnd