php 如何解决“致命错误:找不到‘MySQLi’类”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/666811/
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
How to solve "Fatal error: Class 'MySQLi' not found"?
提问by Tylor
I am doing a tutorial and am getting this error:
我正在做一个教程并收到此错误:
Fatal error: Class 'MySQLi' not found (LONG URL) on line 8
致命错误:第 8 行找不到“MySQLi”类(长 URL)
The code on line 8 is:
第 8 行的代码是:
$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name);
I saw online someone said to see if it was turned on in my phpinfo(), but there wasn't anything listed in there under for "mysqli".
我在网上看到有人说要查看它是否在我的 phpinfo() 中打开,但是在“mysqli”下没有列出任何内容。
Also, I am running PHP version 5.2.5
另外,我正在运行 PHP 版本 5.2.5
采纳答案by Greg
Sounds like you just need to install MySQLi.
听起来你只需要安装 MySQLi。
If you think you've done that and still have a problem, please post your operating system and anything else that might help diagnose it further.
如果您认为您已经这样做了但仍然有问题,请发布您的操作系统和任何其他可能有助于进一步诊断的信息。
回答by karim79
You can check if the mysqli libraries are present by executing this code:
您可以通过执行以下代码来检查 mysqli 库是否存在:
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'We don\'t have mysqli!!!';
} else {
echo 'Phew we have it!';
}
回答by alexkb
If you're calling "new mysqli(..)" from within a class that is namespaced, you might see a similar error Fatal error: Class 'foo\bar\mysqli' not found in. The way to fix this is to explicitly set it to the root namespace with a preceding backslash like so:
如果您从命名空间的类中调用“new mysqli(..)”,您可能会看到类似的错误Fatal error: Class 'foo\bar\mysqli' not found in。解决此问题的方法是使用前面的反斜杠将其显式设置为根命名空间,如下所示:
<?php
$mysqli = new \MySQLi($db_server, $db_user, $db_pass, $db_name);
回答by catawampus
In addition to uncommenting the php_mysqli.dllextension in php.ini, also uncomment the extension_dirdirective in php.iniand specify your location:
除了取消对php_mysqli.dll在扩展php.ini中,也取消注释的extension_dir指令在php.ini中,并注明您的位置:
extension_dir = "C:\software\php\dist\ext"
This made it work for me.
这使它对我有用。
回答by user3839088
回答by vartec
Seems like problem with your installation.
你的安装好像有问题。
- Have you installed MySQLi?
- Have you activated it in php.ini?
- 你安装 MySQLi 了吗?
- 你在php.ini中激活了吗?
回答by Gani
How to Enable mysqli in php.ini
如何在 php.ini 中启用 mysqli
- Edit/uncomment by removing ';'(colon) the following config in php.ini: 1st(uncomment and add config): include_path = "C:\php\includes" 2nd(uncomment): extension_dir = "ext" 3rd(uncomment and edit config): extension=C:/PHP/ext/php_mysql.dll extension=C:/PHP/ext/php_mysqli.dll
- Restart the IIS server
- Make sure that mysql is running on the system.
- 通过删除 ';'(冒号)编辑/取消注释 php.ini 中的以下配置: 1st(取消注释并添加配置):include_path = "C:\php\includes" 2nd(取消注释):extension_dir = "ext" 3rd(取消注释并编辑配置):extension=C:/PHP/ext/php_mysql.dll extension=C:/PHP/ext/php_mysqli.dll
- 重新启动 IIS 服务器
- 确保 mysql 正在系统上运行。
How to load php.ini file
如何加载php.ini文件
- Rename any one of the file php.ini-production/php.ini-development to php.ini from C:\PHP(note now the extention will be ini i.e "php.ini").
- After renaming to php.ini file restart server
- See the changes in http://localhost/phpinfo.php
- 将文件 php.ini-production/php.ini-development 中的任何一个从 C:\PHP 重命名为 php.ini(注意现在扩展名将是 ini,即“php.ini”)。
- 重命名为php.ini文件后重启服务器
- 查看http://localhost/phpinfo.php 中的更改
回答by John
I thought I might help anybody with the same problem using Namesco servers. I have been trying to fix this problem after moving a database from my local server on home pc to namesco. They would not assist they said it was a coding issue.
我想我可以帮助任何人使用 Namesco 服务器遇到同样的问题。将数据库从家用 PC 上的本地服务器移动到 Namesco 后,我一直在尝试解决此问题。他们不会帮助他们说这是一个编码问题。
- However, it was simple to fix from their CPANEl LINUX hosting interface.
- Click on php.
- then click on php modules and from their list of preinstalled modules just click the box for mysqli.
- Then click save. (No need to change code if it worked(s) on another server.)
- 然而,从他们的 CPANEl LINUX 托管界面修复很简单。
- 点击php。
- 然后单击 php 模块,然后从它们的预安装模块列表中单击 mysqli 框。
- 然后点击保存。(如果它在另一台服务器上工作,则无需更改代码。)
Unfortunately, their support articles were a waste of time. After reading this I went to admin interface with a new determination.
不幸的是,他们的支持文章是在浪费时间。读完这篇文章后,我带着新的决心进入了管理界面。
Thank you, everybody.
谢谢大家。
回答by reyqueson
If you are on Docker...
如果你在 Docker 上......
Inside php-container RUN:
在 php-container RUN 中:
#docker-php-ext-install mysqli
#apachectl restart

