Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

when you install php you get php-development.ini and php-prodcution.ini . You need to rename one of the two (depending on whether the environment is for development or production) to php.ini apokryfos Feb 3, 2019 at 8:56

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.

There are 2 things to be done if you are using 5.3.0 and later version of php. 1. Uncomment and set right path to extension_dir = "ext" Basically set the path where you find ext filder in php even if its in same folder from where you are running php-cgi.ex

  • uncomment mysqli library extention extension=mysqli
  • Note: uncommenting in this php.ini file is by removing starting ; from the line.