php mysqli not found,Fatal error: Class 'MySQLi' not found

颜功
2023-12-01

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

I am doing a tutorial and am getting this error: Fatal error: Class 'MySQLi' not found (LONG URL) on line 8

The code on line 8 is: $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error());

I saw online someone said to see if it was turned on in my phpinfo(), but there wasn't anything listed in there under for "mysqli".

Also, I am running PHP version 5.2.5

回答1:

Sounds like you just need to install MySQLi.

If you think you've done that and still have a problem, please post your operating system and anything else that might help.

回答2:

You can check if the mysqli libraries are present by executing this code: if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) { echo 'We don\'t have mysqli!!!'; } else { echo 'Phew we have it!'; }

回答3:

If you are on Ubuntu, run: sudo apt-get install php5-mysqlnd

回答4:

If you're calling "new mysqli(..)" from within a class that is namespaced, you might see a similar error Fatal error: Class 'foo\bar\mysqli' not found in. The way to fix this is to explicitly set it to the root namespace with a preceding backslash like so:

回答5:

In addition to uncommenting the php_mysqli.dll extension in php.ini, also uncomment the extension_dir directive in php.ini and specify your location: extension_dir = "C:\software\php\dist\ext"

This made it work for me.

回答6:

My OS is Ubuntu. I solved this problem by using: sudo apt-get install php5-mysql

回答7:

Seems like problem with your installation. Have you installed MySQLi?

Have you activated it in php.ini?

回答8:

You can use a handwritten MYSQLi class, so you don't need to install mysqli. It's the only solution if you don't own the server.

回答9:

Some distributions (such as Gentoo) support multiple installations of PHP, and you have to make sure you're using one with mysqli installed and enabled.

On Gentoo, I had installed a new PHP (with the mysqli USE flag enabled), but I needed to activate the new version of PHP (since the old one must have been missing mysqli): # eselect php list apache2 [1] php5.3 * [2] php5.5 # eselect php set apache2 2 You have to run `/etc/init.d/apache2 restart' for the changes to take effect # /etc/init.d/apache2 restart

回答10:

host, $this->user, $this->pass, $this->db); if (mysqli_connect_error()) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } } } ?>

回答11:

This solved the initial 'not found' error for me. Note the backslash, works like a dream now. Only necessary when using a namespace but who doesn't nowadays?

$mysqli = new \MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error());

回答12:

I checked all above and it didn't work for me,

There are some steps I found.

I used PHP Version 5.5.9-1ubuntu4.17 on Ubuntu 14.04

First check the folder #ls /etc/php5/mods-available/ json.ini mcrypt.ini mysqli.ini mysql.ini mysqlnd.ini opcache.ini pdo.ini pdo_mysql.ini readline.ini xcache.ini

If it did not contain mysqli.ini, read other answer for installing it,

Open php.ini find extension_dir

In my case , I must set extension_dir = /usr/lib/php5/20121212

And restart apache2 : /ect/init.d/apache2 restart

回答13:

I thought I might help anybody with the same problem using Namesco servers. I have been trying to fix this problem after moving a database from my local server on home pc to namesco. They would not assist they said it was a coding issue. However, it was simple to fix from their CPANEl LINUX hosting interface.

Click on php.

then click on php modules and from their list of preinstalled modules just click the box for mysqli.

Then click save. (No need to change code if it worked(s) on another server.)

Unfortunately, their support articles were a waste of time. After reading this I went to admin interface with a new determination.

Thank you, everybody.

回答14:

The PHP zip includes most of the commonly used extensions (*.dll on windows such as php_mysqli.dll) under the \ext directory, however they are not enabled by default. You might be getting this Fatal Error when trying to use MySQLi: ( ! ) Fatal error: Uncaught Error: Class 'mysqli' not found in C:\myProject\ class.Database.php on line 24

To enable extensions, open php.ini (you might need to first copy php.ini-development as php.ini), and un-comment (or add) these two lines: extension_dir = "ext"

And any particular extensions you are getting Fatal Errors for, i.e. for mysqli: extension=mysqli

 类似资料:

相关阅读

相关文章

相关问答