我有两个参数错误:
mysqli_select_db()期望参数1为mysqli,给定
为nullmysqli_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());
答案 0 :(得分:1)
在设置mysqli_set_db
之前,您正在呼叫$this->link
。另外mysqli_error
需要传递给它的数据库对象:
mysql_error($this->link)
答案 1 :(得分:0)
public function Connect()
{
$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());
$this->connected = true;
}
mysqli_connect必须放在mysqli_select_db之前(需要$ this->链接,mysqli_connect的结果)