Mysqli class not found. Using percona, php5-fpm, n

2019-02-26 22:45发布

问题:

Fatal error: Class 'TKStdlib\mysqli' not found in /var/www/tk-browser-app/application/library/tk-stdlib/DbAbstract.php on line 28

It sounds like I need mysqli installed. Yea I know, but it says it's installed when I do "php -m". It's in my php.ini file in php5-fpm as "extension=mysqli.so".

I find this guide http://www.php.net/manual/en/mysqli.installation.php quite hard to follow. Where is the ./configure file supposed to be? Is that for php5-mysql or does it hold true for percona mysql also?

回答1:

You've set your script into a namespace and it's looking for the class in that namespace.

You can work around this by explicitly trying to reference the mysqli class as a global class:

$db = new \mysqli( ... );

For more on this, see http://php.net/manual/en/language.namespaces.fallback.php which says:

Class names always resolve to the current namespace name.