php - Fatal error: Call to undefined function mysqli_connect()

For 2 days now I'm trying to solve this, but unfortunately no result. Let me tell you my story about the problem. I've bulid an application on a site, and the application deals with the reviews. But, I'm trying to put it on another site, and I copyed the php files, the sql file from the old site, and moved them to the new site (they are on different FTP servers). When I'm trying to go to the pages from the application, I receive this FATAL ERROR:
Fatal error: Call to undefined function mysqli_connect()
The code that I wrote to connect to the database is this (with hidden credentials):
$con = mysqli_connect("","*the_name*","*the_pass*","*the_database*");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Why do I get the error? It works on the old server, and the code I think it's not the problem, because it works on localhost, and on the new server it doesn't. Can anyone help me?
Answer
Solution:
Simply do it
sudo apt install php-mysqli
It works perfectly and it is version independent
Answer
Solution:
If you host the server yourself, in the php.ini file remove the semicolon in front of the extension extension=php_mysqli.dll
Answer
Solution:
On Ubuntu I had to installphp5 mysql
extension:
apt-get install php5-mysql
Answer
Solution:
Happens when php extensions are not being used by default. In your php.ini file, change;extension=php_mysql.dll
to extension=php_mysql.dll
.
**If this error logs, then add path to this dll file, egextension=C:\Php\php-???-nts-Win32-VC11-x86\ext\php_mysql.dll
Do same forphp_mysqli.dll
andphp_pdo_mysql.dll
. Save and run your code again.
Answer
Solution:
Late to the conversation...
If you have the module installed and set your PHP.INI file properly, check your apache error log for something like the following:
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysqli.dll' - The specified module could not be found.
In this case, your extension directory is not what you think it is. You may neeed to set it explicitly, like so:
extension_dir="C:\xampp\php\ext"
Answer
Solution:
Mine was a bit different for php7 on centos7.
In /etc/php.ini
; extension=mysqli
to
extension=mysqli
Answer
Solution:
If you host the server yourself, and that server happens to be Apache, you can also get this error even if you have uncommentedextension=php_mysqli.dll
in php.ini.
You also need to tell Apache where to find php.ini by using thePHPIniDir
directive in Apache's httpd.conf
AddHandler application/x-httpd-php .php
PHPIniDir "<path-to-folder-where-php-ini-lives>"
Answer
Solution:
On Raspberry Pi I had to install php5 mysql extension.
apt-get install php5-mysql
After installing the client, the webserver should be restarted. In case you're using apache, the following should work:
sudo service apache2 restart
Answer
Solution:
if you use ubuntu 16.04 (maybe and above),you have this module already but not enabled by default. Just do this:
sudo phpenmod mysqli
Answer
Solution:
There is no error in the, but the mysqli PHP extension is not installed on your machine. Please contact your service provider to fix this issue.
Answer
Solution:
Mysqli isn't installed on the new server. Run phpinfo() to confirm.
<?php
phpinfo();
Answer
Solution:
So this may not be the issue for you, but I was struggling with this error. I discovered what was causing my problem, though I can't really explain as to why.
For me, mysqli_connect was working fine where the connection was made on pages in any various sub-directory. For some reason though, the same code referenced on pages in the root directory was returning this error. The strange thing is that it was working fine on my localhost environment in MAMP in the root directory, however on my shared host it was not.
After struggling to figure out what was giving me "Error 500" white screen from this "PHP Fatal Error," I went through the code and stumbled upon this code in the error handling that was suggested by the PHP Manual (https://www.php.net/manual/en/mysqli.error.php).
if (!mysqli_query($link, "SET a=1")) {
printf("Error message: %s\n", mysqli_error($link));
}
I randomly decided to remove it and, voila, connection to the database working in root directories. Maybe someone smarter than me can explain this, for anyone struggling with a similar issue.
Answer
Solution:
I followed below link to fix this problem. Make sure to enable following Module.
php -r 'phpinfo();' | grep -i mysqli
Link : https://askubuntu.com/questions/773601/php-mysqli-extension-in-ubuntu-16-04-not-working-after-upgrade-to-version-7-0-6
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the requested url was not found on this server. xampp
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.