我得到以下警告警告使用的mysqli和PHP類
Warning: mysqli::mysqli(): in E:\xampp\htdocs\control\validate.php on line 28
有了下面的代碼
class Validator
{
private $username;
private $password;
private $port;
private $IP;
private $database;
private $mysqli;
public function __construct()
{
$this->username = "root";
$this->password = "root";
$this->port = 3006;
$this->IP = "localhost";
$this->database = "users";
}
private function connect()
{
$this->mysqli = new mysqli($this->IP, $this->username, $this->password, $this->database, $this->port); //error here
if($this->mysqli->connect_errno)
return false;
else
return true;
}
public function validateUser($ID, $PWD)
{
if(!$this->connect())
redirect("login.php?error=mysqli_cant_connect");
}
}
我打電話從連接的ValidateUser()像這樣
$validator = new Validator;
$validator->validateUser($_POST["id"], $_POST["pass"]);
我看着整個互聯網和每一個線程都可以找到,但無法得到答案,任何幫助嗎?我仍然對PHP類和mysqli不熟悉,之前我已經使用了一些mysql擴展,並且在當前的設置上工作得很好。
將'connect()'變成'public' – user3091574
what'mysqli_connect_error()'? –
@ChristianGollhardt Sec –