php 致命错误:调用未定义的函数 mysqli_connect()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25281467/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:45:45  来源:igfitidea点击:

Fatal error: Call to undefined function mysqli_connect()

phpmysqlftp

提问by Emi

For 2 days now I'm trying to solve this, but unfortunately no result. Let me tell you my story about the problem. I've bulid an application on a site, and the application deals with the reviews. But, I'm trying to put it on another site, and I copyed the php files, the sql file from the old site, and moved them to the new site (they are on different FTP servers). When I'm trying to go to the pages from the application, I receive this FATAL ERROR:

现在 2 天了,我试图解决这个问题,但不幸的是没有结果。让我告诉你我关于这个问题的故事。我在网站上构建了一个应用程序,该应用程序处理评论。但是,我试图把它放在另一个站点上,我从旧站点复制了 php 文件和 sql 文件,并将它们移动到新站点(它们位于不同的 FTP 服务器上)。当我尝试从应用程序转到页面时,我收到此致命错误:

Fatal error: Call to undefined function mysqli_connect()

致命错误:调用未定义的函数 mysqli_connect()

The code that I wrote to connect to the database is this (with hidden credentials):

我编写的连接数据库的代码是这样的(带有隐藏的凭据):

$con = mysqli_connect("","*the_name*","*the_pass*","*the_database*");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

Why do I get the error? It works on the old server, and the code I think it's not the problem, because it works on localhost, and on the new server it doesn't. Can anyone help me?

为什么我收到错误?它在旧服务器上工作,我认为代码不是问题,因为它在本地主机上工作,而在新服务器上却没有。谁能帮我?

回答by Dave O'Dwyer

If you host the server yourself, in the php.inifile remove the semicolon in front of the extension extension=php_mysqli.dll

如果您自己托管服务器,请在php.ini文件中删除扩展名 extension=php_mysqli.dll前面的分号

回答by Jo?o Pimentel Ferreira

Simply do it

简单地做

sudo apt install php-mysqli

sudo apt install php-mysqli

It works perfectly and it is version independent

它完美运行并且与版本无关

回答by Zoran

For CentOS, do:

对于CentOS,请执行:

sudo yum install php-mysqli

回答by Rehmat

On Ubuntu I had to install php5 mysql extension.

在 Ubuntu 上,我必须安装 php5 mysql 扩展。

apt-get install php5-mysql

apt-get 安装 php5-mysql

回答by RemyG

Happens when php extensions are not being used by default. In your php.ini file, change
;extension=php_mysql.dll
to
extension=php_mysql.dll.

**If this error logs, then add path to this dll file, eg
extension=C:\Php\php-???-nts-Win32-VC11-x86\ext\php_mysql.dll

Do same for php_mysqli.dlland php_pdo_mysql.dll. Save and run your code again.

默认情况下未使用 php 扩展时发生。在 php.ini 文件中,更改
;extension=php_mysql.dll

extension=php_mysql.dll.

**如果此错误记录,则添加此 dll 文件的路径,例如,
extension=C:\Php\php-???-nts-Win32-VC11-x86\ext\php_mysql.dll

php_mysqli.dll和执行相同操作php_pdo_mysql.dll。保存并再次运行您的代码。

回答by Jahmic

Late to the conversation...

谈话迟到...

If you have the module installed and set your PHP.INI file properly, check your apache error log for something like the following:

如果您安装了该模块并正确设置了您的 PHP.INI 文件,请检查您的 apache 错误日志中的类似内容:

PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_mysqli.dll' - The specified module could not be found.

PHP 警告:PHP 启动:无法加载动态库 'C:\php\ext\php_mysqli.dll' - 找不到指定的模块。

In this case, your extension directory is not what you think it is. You may neeed to set it explicitly, like so:

在这种情况下,您的扩展目录不是您认为的那样。您可能需要明确设置它,如下所示:

extension_dir="C:\xampp\php\ext"

回答by doapydave

Mine was a bit different for php7 on centos7.

对于centos7上的php7,我的有点不同。

In /etc/php.ini

在 /etc/php.ini

; extension=mysqli

; 扩展名=mysqli

to

extension=mysqli

扩展名=mysqli

回答by Yu Jiaao

if you use ubuntu 16.04 (maybe and above),you have this module already but not enabled by default. Just do this:

如果您使用 ubuntu 16.04(可能及更高版本),则您已经拥有此模块,但默认情况下未启用。只需这样做:

sudo phpenmod mysqli

回答by AaronDanielson

If you host the server yourself, and that server happens to be Apache, you can also get this error even if you have uncommented extension=php_mysqli.dllin php.ini.

如果您自己托管服务器,并且该服务器恰好是 Apache,那么即使您extension=php_mysqli.dll在 php.ini 中取消注释,您也会收到此错误。

You also need to tell Apache where to find php.ini by using the PHPIniDirdirective in Apache's httpd.conf

您还需要使用PHPIniDirApache 的 httpd.conf 中的指令告诉 Apache 在哪里可以找到 php.ini

AddHandler application/x-httpd-php .php
PHPIniDir "<path-to-folder-where-php-ini-lives>"

回答by Utkarsh Dixit

There is no error in the, but the mysqli PHP extension is not installed on your machine. Please contact your service provider to fix this issue.

中没有错误,但是您的机器上没有安装mysqli PHP 扩展。请联系您的服务提供商以解决此问题。