PHPUnit, Fatal error: class mysqli not found

I have a similar problem as described here :

Everything works as I expected; my code accesses the database and prints output regardless of whether I run from the command line interface or from a web browser. The same result. If I run it in Eclipse using PHPUnit, I get the error:

Multiple annotations found at this line:
    - Fatal error: Class 'mysqli' not found
    - Occurrence of 'connection'

      

What are the points in the next line:

This code outputs "Yes".

$connection = new \mysqli(HOST, USER, PASS, DATABASE);

if (extension_loaded('mysqli')) {
    echo "Yes";
}
else {
    echo "No";
}

      

One more note: I am using my own namespace in the class where the above code resides. My unit tests are in the global namespace.

I followed the steps in the URL above but alas to no avail. :(

Running this on the command line gives no errors:

php -r "new mysqli();"

      

Please help me understand this problem here?

+3


source to share


1 answer


I'm not sure if you configured your file php.ini

with the correct path, either a DLL or a shared file (.so). Try running, if you are using Unix / Linux, on the command line,

$> php -i | grep mysqli

      

and see if it says anything installed or create a PHP script



<?php phpinfo(); ?>

Run the script program and check if it loaded correctly. If you are sure that it is indeed installed, try checking the php.ini file if it was loaded correctly by checking the "php.ini" extension section.

Check also when running PHPUnit if it is on the command line, because you may have a different path for php.ini vs your php.ini when running in web mode.

0


source







All Articles