Class 'mysqli' not found

Posted on 2013-12-07
Medium Priority
Last Modified: 2013-12-13
Fatal error: Class 'mysqli' not found in C:\wamp\bin\apache\apache2.4.2\htdocs\SAMSCopy\include\databaseclass.inc on line 16

I have these lines in my database class

16    if(!$this->cxn = new mysqli($host,$user,$passwd))
17   {
18       throw new Exception("Database is not available.
19                            Try again later.");
20       email("dbadmin@ourplace.com","DB Problem",
21          "MySQL server is not responding. ".
22           $this->cxn->error());
23       exit();
24    }
25    $this->host = $host;
26    $this->user = $user;
27    $this->password = $passwd;

I get this error

Fatal error: Class 'mysqli' not found in C:\wamp\bin\apache\apache2.4.2\htdocs\SAMSCopy\include\databaseclass.inc on line 16

Line 16 is the first line of
Question by:johnecollins
  • 6
  • 5
  • 3
  • +1
LVL 17

Expert Comment

by:Kent Dyer
ID: 39703822
Have you installed mysqli in the first place?

This should help you with the step-by-step to troubleshoot and to get you going - http://www.php.net/manual/en/mysqli.installation.php
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39703883
Click on the WAMP Manager icon and look for PHP extensions.  Click on 'php_mysqli' to enable it and restart everything.

Author Comment

ID: 39704047

Thank you for your response, I hadn't realised that I could setup extensions within Wamp Manager, I did as you suggested and I have already enabled mysqli.dll and disabled MySQL.dll in php.ini.

It's a poor day when you don't learn something new ;-)

I have also checked the extension_dir = "c:/wamp/bin/php/php5.4.3/ext/" and that is correct.

Thank you for your response, I have read the suggested page and the gist of it appears to be that I should use MySql Native Driver.

However in the following quote from that posting


If when starting the web server an error similar to the following occurs: "Unable to load dynamic library './php_mysqli.dll'", this is because php_mysqli.dll and/or libmysql.dll cannot be found by the system.

PHP 5.3.0+

On Windows, for PHP versions 5.3 and newer, the mysqli extension is enabled and uses the MySQL Native Driver by default. This means you don't need to worry about configuring access to libmysql.dll. "


The quoted note sounds like my problem it appears that the php_mysqli.dll, but I am using PHP 5.4.3 the paragraph after the note, PHP 5.3.0+ says the MySQL Native Driver is default.

So I'd be grateful if there is any further help that either of you could suggest

Thanks a lot

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

LVL 111

Expert Comment

by:Ray Paseur
ID: 39704260
Run this script, shown here in its entirety.  The various extensions are listed in alphabetical order.  Scroll down to about the mid-point to see the MySQL and MySQLi information.

<?php phpinfo();

Open in new window

Here are the things I think you need to read and check carefully.

"The mysqli extension is built using the PHP extension framework, its source code is located in the directory ext/mysqli."

"In order to have these functions available, you must compile PHP with support for the mysqli extension."

"For the mysqli extension the installer also edited php.ini so that the extension was enabled..."

-->Compare your settings to the system defaults.

I use Linux PHP 5.4.22.  Here is what I see in phpinfo()
MySQL/MySQLi Excerpt from phpinfo() display

Author Comment

ID: 39704429
Hi Ray,

Thank you for your response I have run phpinfo() and put the result into the attached word file.

I do not have a section for mysqli, as you do.

From Wamp Manager I ran phpmyadmin as wel and have attached a screen print of the error I got.

I had a look at the articles you suggested and I am sorry I did not find any clues for me there.

In the phpinfo output it shows mysqli.dll commented enabled - semi-colon removed from start of line. I have checked the extension_dir and that is correct.

In past deployments this was all I needed to do to be able to access MySQL databases.

The only I thought I could do was put the extension_dir into my system_path. But not sure if it would help.
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39704436
Did you restart the WAMP server?  Extension changes won't show up in 'phpinfo()' until you do.
LVL 111

Expert Comment

by:Ray Paseur
ID: 39704529
According to phpinfo() It looks like you do not have MySQL nor MySQLi installed.  Check this page, and also those linked in the left sidebar.  

Maybe also check the contents of php.ini?  Once you've got everything the way it ought to be, restart everything and try again.

Author Comment

ID: 39704713
Hi Dave,

I used the Wamp Manager to stop the services, made changes in the php.ini and restarted the services the listing of php.ini in phpinfo had changed between the two executions.

I have since restarted the laptop, several times, but to no avail


LVL 84

Expert Comment

by:Dave Baldwin
ID: 39704723
At this point, I would save any code that you written and re-install WAMP.  Actually what I have done was rename the C:\wamp to C:\wampold and do a re-install.  If there is any possibility that your WAMP download was corrupted, you might want to re-download it.

Then after it is re-installed, just enable 'mysqli' without disabling anything else and see how it works.

The standard WAMP install includes copies of all of the Windows dlls for the standard extensions including 'php_mysql' and 'php_mysqli'.
LVL 111

Expert Comment

by:Ray Paseur
ID: 39704884
This situation is kind of the "dictionary picture" of why I use a professional hosting company for my sites.   I don't install PHP locally.  For me a build is an FTP transfer of all the relevant files, from my local machine where I edited the PHP scripts, to the server that I access over the internet.  Not only do I make all of my tests in an environment that is very, very close to the deployment environment, but I have access to professionals who set up and maintain both the test and deployment environment.  This advantage costs me literally pennies per day.  

It's worth thinking about doing something like this instead of struggling with missing features and broken installs.  Being a productive PHP programmer is not the same as installing PHP.  I am the former, and my hosting company is proficient at the latter.  This seems to be a good division of labor.
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39705102
As a person who works for a lot of small businesses, I'm going to have to disagree with you a little.  When they hire me, I have to deal with whatever hosting and PHP version they have running.  If you have only one client and/or you always get to choose the hosting, you may not have to deal with such things.  I have clients with hosting on a couple of versions of Windows and several versions of Linux.  At least I only have one client left running PHP 4.4.

I have learned a lot from having and installing PHP and web servers on many different systems.  I have PHP running on Windows, Linux and Mac systems and I have Apache running on all of them along with IIS on Windows.  I have WAMP installed on one machine and XAMPP installed on another.  I have 12 different installations of PHP and web servers on my machines here.

WAMP installs All the Windows PHP extension dlls as do all Windows PHP installs.  It doesn't enable all of them.  Normally WAMP is a simple install of less than 5 minutes that includes Apache, PHP, MySQL, phpMyAdmin and several other programs.  It normally just comes up running.  

You can, as several questions here have shown, click on things and make it stop working.  However, you can do that with any install including PHP on Linux.  At that point, rather than trying to diagnose something I can't see, I recommend that they re-install WAMP.

Author Comment

ID: 39710197
Hi Ray,

I understand your point of view, having someone else deal with these sort of issues does appeal a lot.

Hi Dave,

I also understand your point of view, having the ability to respond to client's needs is always a good plan.

I did as you suggested and renamed my wamp directory, downloaded a different version of WAMP. I followed the instructions and installed the package.

I ran the example html that comes with the package, and got the It Works! Legend.

I then recreated my project in Netbeans my IDE, I updated php.ini and httpd.conf tried out my project again and got Fatal Error Class MySQLi not found.

I then googled the error and comfortingly I am not the first and I am not alone. There were many references to the error but I couldn't see any solutions that would help me. Some of the contributors were using IIS, or Linux and one suggested he was going to learn pdo and use that in future.

I also searched php.net and found it on there amongst their FAQs. I found this bit of code and ran it in my php directory C:\wamp\bin\php\php5.3.13>
php -m -d extension_dir=ext -d extension=php_mysqli.dll

I first got an alert type dialog box that was titled warning with a message Module 'mysqli' already loaded when I pressed ok I got this.

PHP Warning:  Module 'mysqli' already loaded in Unknown on line 0

Warning: Module 'mysqli' already loaded in Unknown on line 0
[PHP Modules]

[Zend Modules]

In my index.php I put this code that also tested whether mysqli is loaded

if (function_exists('mysqli_init') && extension_loaded('mysqli')) {
    echo 'we got it';
} else {
    echo 'no mysqli :(';

It always comes up "no mysqli :("

I am not sure what to do now but I think I might  sleep on it for the and see if I can't get some of my project SQL done.

Thank you all 3 of you very much for your assistance, it was invaluable.

LVL 84

Accepted Solution

Dave Baldwin earned 2000 total points
ID: 39710246
Your code will always come up "no mysqli :(" because there isn't any function called 'mysqli_init'.

Go to 'localhost' and click on 'phpMyAdmin' and let me know if it works.  You should have done that before changing 'php.ini' and 'httpd.conf'.

Author Closing Comment

ID: 39712547
Hi Dave,

I have renamed my Wamp directory, downloaded wampserver and reinstalled it.

phpmyadmin did not work phpinfo did work example page in doc_root also worjed.

I slowly progressed through the installation enabled mysqli run my page and the offending error did not come up.

I found mysqli_init() and found it on one of the W3 sites and my block of code outputs the success message indicating mysqli loaded..

Fortunately you were patient with me and so I am not sure where I made a mistake in my previous installs but I can get on with my so thank you for your assistance.

Ray and kdyer, thank you for help with this.

LVL 84

Expert Comment

by:Dave Baldwin
ID: 39712580
You're welcome, thanks for the points.  If you ever have to do something like this again where you have to install multiple pieces of software, I suggest you check each one as you install it to make sure it works by itself before you add the next piece.  On every WAMP and XAMPP install I've done (about 6 of them), phpMyAdmin always came up working.

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question