Red Hat Linux Server, Apache 2.2, PHP 5.5.4
When I run this in the command line, everything seems to be fine:
php -r '$mysqli = new mysqli("127.0.0.1", "un", "pw", "things", "3306");'
At the same time, I have a .php document which doesn't run. I get this error...
PHP Fatal error: Class 'mysqli' not found in [/path/to]/vars.php on line 2
from this code:
<?php
$mysqli = new mysqli("localhost", "un", "pw", "things", "3306");
?>
Other .php pages (which don't use mysqli) work fine. Any idea what's going on here? Thanks in advance.
Check if MySQLi is Installed You can do that by visiting a phpinfo() page that you made, or by running this command: php -m | grep mysqli.
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.
The oldest one uses the MySQL extension, which was deprecated as of PHP 5.5 and fully removed in PHP 7. The mysql() function no longer works in PHP 7. It has been replaced with mysqli().
Like I said, today I was facing the exact same issue with Apache 2.4, PHP 5.5.12, Windows Server 2008.
But I was able to solve this.
Diagnostics:
I ran phpinfo()
in both my command prompt as well as on the web server/browser and noticed that path of the php.ini
files were different in both. Now, I realised that I need to force set the path to the php.ini
file in Apache.
Solution:
I fixed this by pointing to the correct php.ini
and dll files on my Apache server.
In the httpd.conf
file I wrote these lines in sequence.
PHPIniDir "C:/path/php/php5.5.12"
LoadFile "C:/path/php/php5.5.12/php5ts.dll"
LoadModule php5_module "C:/path/php/php5.5.12/php5apache2_4.dll"
The first line alone fixed the issue.
I've asked almost the same question on Unix Stack Exchange; this was how the issue got resolved.
Sometimes restarting Apache has no effect even after rebooting, but stopping the httpd
service and starting it again worked for me:
On Fedora
sudo systemctl stop httpd && sudo systemctl start httpd
On systems without systemd
(like Ubuntu) you can probably can use something like this (didn't test it):
sudo service apache2 stop && sudo service apache2 start
reference: How to install php + mysql on Fedora?
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