找不到类 'mysqli' PHP v5.6.7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29503723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'mysqli' not found PHP v5.6.7
提问by Don Subert
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:
在我的 Windows 7 机器上,使用 PHP v5.6.7 和 MySQL v5.6.23,并使用 PHPStorm 8,我试图实例化一个 mysqli 对象。当我尝试时,我得到:
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 herethat 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 类时引起的。我更改了代码以更正此问题,但问题仍然存在
$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).
我读到这个问题有时是由于未启用 mysqli 扩展而引起的。但是,我使用的是 PHP 5.6.7 版,并且 mysqli 扩展在 5.3 及更高版本上默认启用(根据此处)。
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:
只是可以肯定,我已经验证php.ini-development
,并php.ini-production
有extension_dir = "C:/PHP/php-5.6.7/ext"
和有分号从行中删除:
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:
[附加信息] 我找到了一个要运行的测试,根据 phpinfo() 它没有加载配置文件:
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?
出于某种原因,PHPStorm Web 服务器没有在正确的位置寻找 php.ini?
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.
我已经验证这是正确的路径。
采纳答案by Don Subert
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.
scrowler 和 Michael Bush 在上面的评论中指出了答案。我想我会为它创建一个答案,以便有人查看该线程。谢谢,scrowler 和迈克尔布什。
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
.
在php.ini-development
和php.ini-production
文件模板。为了生效,其中之一需要被复制和重命名php.ini
。
回答by Michael Bush
Have you added the PHP installation directory to you environment path
您是否将PHP安装目录添加到您的环境路径中
- 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
- 从开始菜单右键单击我的电脑
- 点击属性
- 找到高级系统设置
- 点击环境变量
- 在系统变量下找到 PATH 添加 C:\php 用你的 PHP 安装目录替换 C:\php;*** 记住路径分隔符
Also check this entry in your php.ini
还要检查您的 php.ini 中的此条目
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "c:/php/ext"