php 如何修复对未定义函数 mysqli_connect() 的调用

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

How to fix call to undefined function mysqli_connect()

phpmysql

提问by Muhammad Azharuddin

I am trying to deploy a php based application online and getting following error:

我正在尝试在线部署基于 php 的应用程序并收到以下错误:

Call to undefined function mysqli_connect() in home/spurdes/public_html/testsites/crimebusters/Repository/SQL_Connection.php on line 27.

Here is line 27:

这是第 27 行:

$this->connection=  mysqli_connect($this->connectionHost,$this->userName,$this->password,$this->dbName);

Here is my phpinfo

这是我的phpinfo

I dont have access to php.init

我无权访问 php.init

回答by user3169497

I was required to move a website from a commercial web host to a virtual server. I am using php and mysql in IIS on Windows Server 2008. I solved the mysqli_connect problem by doing the following.

我需要将网站从商业网络主机转移到虚拟服务器。我在 Windows Server 2008 上的 IIS 中使用 php 和 mysql。我通过执行以下操作解决了 mysqli_connect 问题。

  • I uncommented extension=php_mysql.dll, extension=php_mysqli.dll, and extension=php_pdo_mysql.dll in the php.ini file.
  • 我在 php.ini 文件中取消了 extension=php_mysql.dll、extension=php_mysqli.dll 和 extension=php_pdo_mysql.dll 的注释。

In my php file I had a class with a _construct function that included the mysqli_connect function. This works well in Apache and on the Unix server but not in IIS and Windows Server 2008. Here is the code:

在我的 php 文件中,我有一个包含 mysqli_connect 函数的 _construct 函数的类。这适用于 Apache 和 Unix 服务器,但不适用于 IIS 和 Windows Server 2008。这是代码:

<?php

class MyClass
{
    var $tablename="t_table";       
    var $connection;
    public function __construct() { 
        $this->connection = new MySQLi("host", "user", "password", "dbname", "port")or  die("Error connecting " . mysqli_error($connection));
    }
//functions that use $this->connection and $tablename are here.......
}
?>

Note: No other way of assigning a value to $connection worked for me. This is the result of at least 12 hours of internet searching and trial and error coding. I am a novice coder. It may not be pretty but it works. I hope this helps.

注意:没有其他为 $connection 赋值的方法对我有用。这是至少 12 小时的互联网搜索和试错编码的结果。我是新手编码员。它可能不漂亮,但它有效。我希望这有帮助。

回答by zoonman

You need a mysqli php extension. Contact to hoster or change hosting service.

你需要一个 mysqli php 扩展。联系托管服务商或更改托管服务。

回答by Praveen kalal

You need to add this code in your PHP script

您需要在 PHP 脚本中添加此代码

 dl("mysqli.so");

回答by Sumit Thakur

It is a php vesrion problem

这是一个php版本的问题

  1. you replace mysqli_connect() to mysql_connect()
    or
  2. contact to server guys to upgrade your version
  1. 您将 mysqli_connect() 替换为 mysql_connect()
  2. 与服务器人员联系以升级您的版本