Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'mysqli' not found PHP v5.6.7

On my Windows 7 machine, with PHP v5.6.7 and MySQL v5.6.23, and using PHPStorm 8, I am attempting to instantiate a mysqli object. When I try, I get:

Fatal error: Class 'mysqli' not found in...

I have also run this test, suggested here:

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

The output is:

no mysqli :(

I read here that this problem is sometimes caused when it looks for the mysqli class within a namespace. I changed my code to correct this, but the issue persists

$mysqli = new \mysqli($host, $userName, $password, $database);

I read that this problem is sometimes caused when the mysqli extension is not enabled. However, I am using PHP version 5.6.7, and the mysqli extension is enabled by default on versions 5.3 and newer (according to here).

Just to be sure, I have verified that php.ini-development and php.ini-production have extension_dir = "C:/PHP/php-5.6.7/ext" and have the semi-colon removed from the lines:

extension=php_mysql.dll
extension=php_mysqli.dll 

[Additional information] I found a test to run and according to phpinfo() it is not loading a configuration file:

Configuration File (php.ini) Path   C:\Windows
Loaded Configuration File   (none)
Scan this dir for additional .ini files (none)
Additional .ini files parsed    (none)

For some reason, the PHPStorm web server is not looking for php.ini in the right place?

I have this setting in the "Interpreter options" per this:

--php-ini C:\PHP\php-5.6.7\php.ini

I have verified that this is the correct path.

like image 423
Don Subert Avatar asked Apr 08 '15 00:04

Don Subert


2 Answers

scrowler and Michael Bush pointed out the answer in comments above. I thought I'd create an answer for it for the benefit of someone viewing the thread. Thanks, scrowler and Michael Bush.

The php.ini-development and php.ini-production files are templates. In order to have effect, one of them needs to be copied and renamed php.ini.

like image 107
Don Subert Avatar answered Nov 20 '22 06:11

Don Subert


Have you added the PHP installation directory to you environment path

  • right click on my computer from the start menu
  • click on properties
  • find advanced system settings
  • click on environment variables
  • under system variables find PATH add C:\php replacing C:\php with your PHP installation directory; *** remember the path separator

Also check this entry in your php.ini

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "c:/php/ext"
like image 5
Michael Bush Avatar answered Nov 20 '22 06:11

Michael Bush