Home > Net >  Unable to load mysqli
Unable to load mysqli

Time:08-08

Upgrade to Ubuntu server 22.04. I'm unable to use mysqli() from a php script

Uncaught Error: Call to undefined function mysqli_connect()

I have php8.1-mysql installed, but I don't have a /etc/php/8.1/mods-available/mysqli.ini In fact I only have a few ini files in /etc/php/8.1/mods-available/ I ran apt install --reinstall php-mysql without any success.

CodePudding user response:

That's a common issue with an easy fix. It happens mostly after upgrading from older PHP version to newer.

  1. Install mysqli for PHP8

sudo apt-get install php8.0-mysqli

  1. Restart apache & mysql

sudo /etc/init.d/apache2 restart

sudo /etc/init.d/mysql restart

  1. Check if mysqli is installed and enabled

php -r 'phpinfo();' | grep -i mysqli

  1. Enable mysqli if it's not

sudo phpenmod mysqli

  1. Restart apache again

sudo /etc/init.d/apache2 restart

You might need to enable the extension in your php.ini file. Locate the file php --ini | grep Loaded. Open it and uncomment ;extension=mysqli by removing the semicolon (;). Restart apache again and it should all be working fine.

CodePudding user response:

PHP wasn't working on the command line, so it had nothing to do with apache2. I did an apt purge php* and then did a reinstall of php, which recreated all the ini files.

  • Related