gpt4 book ai didi

php - MySQL错误参数

转载 作者:行者123 更新时间:2023-11-29 00:13:03 25 4
gpt4 key购买 nike

我有两个参数错误:
mysqli_select_db()期望参数1为mysqli,给定空值
mysqli_error()需要1个参数,给定0

class MyMySQLi
{
private $connected = false;
private $hostname = "localhost";
private $username = "root";
private $password = "****";
private $database = "****";
private $link;

public function Connect()
{
mysqli_select_db($this->link,$this->database) or $this->error(mysqli_error());

$this->connected = true;
$this->link = mysqli_connect($this->hostname, $this->username, $this->password) or $this->error(mysqli_error());

}
public function MySQLi($host, $user, $pass, $db)
{
$this->connected = false;
$this->hostname = $host;
$this->username = $user;
$this->password = $pass;
$this->database = $db;
}

public function IsConnected()
{
if ($this->connected)
{
return true;
}

return false;
}

谢谢你!我还有一个错误:
mysqli_error()需要1个参数,给定0
            $this->connected = true;
$this->link = mysqli_connect($this->hostname, $this->username,
$this->password) or $this->error(mysqli_error());
mysqli_select_db($this->link,$this->database) or $this->error(mysqli_error());

最佳答案

在设置mysqli_set_db之前,您正在调用$this->link。还需要传递给它的数据库对象:
mysqli_error

关于php - MySQL错误参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24096777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com