Solved

Class 'mysqli' not found

Posted on 2013-12-07
16
6,255 Views
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
0
Comment
Question by:johnecollins
  • 6
  • 5
  • 3
  • +1
16 Comments
 
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
0
 
LVL 82

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.
0
 

Author Comment

by:johnecollins
ID: 39704047
Dave,

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.

kdyer,
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

"Note:

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. "

endquote

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

John
0
 
LVL 108

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."
http://php.net/manual/en/mysqli.overview.php

"In order to have these functions available, you must compile PHP with support for the mysqli extension."
http://php.net/manual/en/mysqli.requirements.php

"For the mysqli extension the installer also edited php.ini so that the extension was enabled..."
http://php.net/manual/en/mysqli.installation.php#93030

-->Compare your settings to the system defaults.
http://php.net/manual/en/mysqli.configuration.php

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

Author Comment

by:johnecollins
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.
PHP-Version-5.4.3.docx
phpmyadmin-error.docx
0
 
LVL 82

Expert Comment

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

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.  
http://php.net/manual/en/mysql.installation.php

Maybe also check the contents of php.ini?  Once you've got everything the way it ought to be, restart everything and try again.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:johnecollins
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

Thanks

John
0
 
LVL 82

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'.
0
 
LVL 108

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.
0
 
LVL 82

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.
0
 

Author Comment

by:johnecollins
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]
bcmath
calendar
com_dotnet
Core
ctype
date
dom
ereg
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mcrypt
mhash
mysql
mysqli
mysqlnd
odbc
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
Reflection
session
SimpleXML
SPL
standard
tokenizer
wddx
xdebug
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
Xdebug


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.

John
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 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'.
0
 

Author Closing Comment

by:johnecollins
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.

John
0
 
LVL 82

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.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now