I am trying to use mysqli to connect to my MySQL database using mysqli_connect(). However, whenever I grab a reference to my .php file that attempts to connect to the database, it throws a fatal error:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect()
I read that you must delete a semi-colon from php.ini, but my PHP7 folder does not contain a strictly php.ini file. It only has php.ini-development and production; deleting the semi-colons for anything related to mysqli does nothing. For the record, I am also not using XAMPP, or any web server applications of the likes. Instead, I am using PHP's command to run a server:
php -S localhost:8000
I am not sure if that has anything to do with it. Furthermore, when I run phpinfo(), it states:
Loaded Configuration File (none)
How do I get mysqli to work?
If you are using PHP 7 and Ubuntu 16.04 then you can do this:
sudo apt-get update
sudo apt-get install php-mysql
sudo service apache2 restart
It'll automatically enable the mysqli extension for the PHP because connect using mysql is deprecated in PHP 7.
If not an Ubuntu user then you can just rename php-prodcution.ini file to php.ini and enable the extension by removing semicolon in the php.ini file.
extension=php_mysqli.so
Don't forget to restart the server (Apache or Ngnix) after updating php.ini file.
You have to rename one file (php.ini-development or php.ini-production) to php.ini
. That's the file you have to configure. Normally you should rename the production
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With