Fatal error: Class 'MySQLi' not found

I am doing a tutorial and getting this error:

Fatal error: Class 'MySQLi' not found (LONG URL) on line 8

Code on line 8:

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

I saw someone say that it is included in my phpinfo (), but nothing was specified there for "mysqli".

In addition, I am running PHP version 5.2.5

+58
php mysqli
Mar 20 '09 at 16:04
source share
13 answers

Looks like you just need to install MySQLi .

If you think you did this and still have problems, submit your operating system and all that can help.

+58
Mar 20 '09 at 16:07
source share

You can check if mysqli libraries are present by running this code:

 if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) { echo 'We don\'t have mysqli!!!'; } else { echo 'Phew we have it!'; } 
+41
Mar 21 '09 at 21:12
source share

If you are on Ubuntu , run:

  sudo apt-get install php5-mysqlnd 
+31
Mar 20 '14 at 6:35
source share

If you call "new mysqli (..)" from a class with a namespace, you can see a similar Fatal error: Class 'foo\bar\mysqli' not found in . The way to fix this is to explicitly set it to the root namespace with the previous backslash as follows:

 <?php $mysqli = new \MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error()); 
+10
Mar 09 '15 at 2:06
source share

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" 

It made him work for me.

+8
Oct 22 '10 at 19:16
source share

My OS Ubuntu . I solved this problem using:

 sudo apt-get install php5-mysql 
+4
Jul 15 '14 at 2:23
source share

Sounds like a problem with your installation.

  • Have you installed MySQLi?
  • Have you activated it in php.ini?

http://www.php.net/manual/en/mysqli.installation.php

+2
Mar 20 '09 at 16:08
source share

You can use the MYSQLi handwritten class , so you do not need to install mysqli. This is the only solution if you do not own the server.

+1
Aug 17 '12 at 12:33
source share

Some distributions (such as Gentoo ) support multiple PHP installations, and you must make sure that you are using one with mysqli installed and enabled.

In Gentoo, I installed new PHP (with the USE mysqli flag enabled), but I needed to activate a 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 
0
Nov 16 '13 at 1:55
source share
 <?php /* If the error is due to calling mysqli in a class */ class dbconnect extends mysqli{ private $host = 'localhost'; private $user = 'root'; private $pass = ''; private $db = 'test'; public function __construct() { parent::__construct($this->host, $this->user, $this->pass, $this->db); if (mysqli_connect_error()) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } } } ?> 
0
Oct 20 '14 at 11:08
source share

This solved the original β€œnot found” error for me. Note the backslash, now it looks like a dream. Only needed when using the namespace, but who is not now?

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

0
Mar 01 '16 at 17:10
source share

I checked everything above and it didn’t work for me,

There are several steps that I have found.

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

Check the folder first

 #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 does not contain mysqli.ini , read another answer to install it,

Open php.ini find extension_dir

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

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

0
Jul 18 '16 at 8:03
source share

I thought I could help someone with the same problem using Namesco servers. I tried to solve this problem after moving the database from my local server to the home computer in namesco. They would not help them say that this is a coding problem.

  • However, it was easy to fix their hosting CPANEl LINUX interface.
  • Click on php.
  • then click on php modules and from their list of preinstalled modules just click the field for mysqli.
  • Then click "Save." (No need to change the code if it worked on another server.)

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

Thanks, everyone.

0
Oct 25 '17 at 15:51
source share



All Articles