8

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?

Thad Josh Tayo
  • 81
  • 1
  • 1
  • 3
  • 1
    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 03 '19 at 08:56

3 Answers3

20

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.

Arti Singh
  • 906
  • 1
  • 6
  • 21
5

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.

KHansen
  • 784
  • 5
  • 21
-2

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

  1. uncomment mysqli library extention extension=mysqli

Note: uncommenting in this php.ini file is by removing starting ; from the line.