Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable mysqli for my PHP script? [duplicate]

Tags:

php

mysqli

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?

like image 422
Thad Josh Tayo Avatar asked Feb 03 '19 07:02

Thad Josh Tayo


2 Answers

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.

like image 72
Arti Singh Avatar answered Nov 05 '22 02:11

Arti Singh


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.

like image 44
KHansen Avatar answered Nov 05 '22 01:11

KHansen