8

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.

8
  • 2
    I think the php.ini-development files are just templates, you should copy the one you want to base your configuration off and place it as appropriate for where PHP will look for the actual file; php.ini Commented Apr 8, 2015 at 0:21
  • Have you restarted all services after making any changes to system files? Plus, have you tried $mysqli = new mysqli ... without the slash? Commented Apr 8, 2015 at 0:30
  • scrowler, thank you for the suggestion. I've done that, but there seems to be an error parsing the php.ini file. I am doing some more research before editing my question. Fred -ii-, I believe PHP doesn't have a running process that needs to be restarted. I believe PHPStorm automatically restarts its internal webserver between runs. I will try rebooting the comp to make sure. I have, indeed tried it with and without the \. Commented Apr 8, 2015 at 0:38
  • I'm running on Wamp and I remember I had to reboot my system in order to make it work after installing it. Could be the same here. Commented Apr 8, 2015 at 0:40
  • 1
    I was just going to mention if you went through their checklist jetbrains.com/phpstorm/help/php-built-in-web-server.html and point #4. Commented Apr 8, 2015 at 0:46

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

If scrowler or Michael Bush wish to post this an an answer before tommorrow, I'll "accept" yours instead.
5

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"

7 Comments

Yes, the php installation is on the system path.
I believe you need to edit your php.ini and change extension_dir from extension_dir = "ext" to extension_dir = "c:/php/ext" or what ever your path is
can you also confirm that you have copied and renamed either php.ini-development or php.ini-production to php.ini
can I see the output of phpinfo()
I have to concentrate on homework for a while. I will get back to this when I can.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.