3

I just deployed my website to a staging environment and am getting the following error:

Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11

At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:

enter image description here

To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?

Code

class DB
{
    public static function GetConnection()
    {
        return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
    }
}

(line 11 is the return new mysql(...);)

Update

I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):

Loaded Configuration File   C:\WINDOWS\php.ini

But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?

Dharman
  • 30,962
  • 25
  • 85
  • 135
drewwyatt
  • 5,989
  • 15
  • 60
  • 106
  • 1
    Please show your code. – Damien Black Feb 18 '14 at 20:33
  • 2
    Try finding `extension=php_mysqli.so` in your `php.ini` (if on a Linux server) `php_mysqli.dll` <=(on a Windows server) and remove comment in front of it. Then restart your webserver after making changes in php.ini - Or you may need to install MySQLi http://www.php.net/manual/en/mysqli.installation.php and see [`this answer`](http://stackoverflow.com/a/670012/) to check. – Funk Forty Niner Feb 18 '14 at 20:43
  • Above comment will solve the problem.If you are new to mysqli then i will suggest to learn pdo which is safe to query the database. – sud_shan Feb 18 '14 at 20:53
  • Is your DB class namespaced? If so, you need `new \mysqli()`? – miken32 Feb 18 '14 at 20:54

3 Answers3

4

I got the error corrected by enabling/editing the following config in php.ini:

1st (uncomment and add config):

include_path = "C:\php\includes"

2nd (uncomment):

extension_dir = "ext"

3rd (uncomment and edit config):

extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Mark
  • 8,046
  • 15
  • 48
  • 78
1

Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache

Karim Lahlou
  • 168
  • 5
0

Christian Mark is right but I think it need:

4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"

5rd login out Computer and login in.

Then it work for me.

If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

Hui Tan
  • 95
  • 1
  • 5
  • Instead of copying php.ini to C:\Windows, you can also just set the PHPRC environment variable to the path(s) of your php.ini ... see http://stackoverflow.com/a/43531113/1593026 for more info – Aaron Wallentine Apr 20 '17 at 23:19