我输入登录详细信息时出现问题我收到此错误
Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\Remake Login Page\Classes\Mysql.php on line 22
Mysql.php的代码:
<?php
require_once 'includes/constants.php';
class Mysql {
private $conn;
function _construct() {
$this->$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die
('There was a problem connecting to the database');
}
function verify_Username_and_Pass($un, $pwd) {
$query = "SELECT *
FROM users
WHERE username = ? AND password = ?
LIMIT 1";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param('ss', $un, $pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
}
希望有人可以帮助我。
提前致谢。
答案 0 :(得分:4)
构造函数方法以双下划线开头。具有单个下划线的方法只是正常的函数名称。
试试这个:
function __construct() {
$this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database');
}
答案 1 :(得分:3)
你的构造函数需要两个下划线。
答案 2 :(得分:2)
您的构造函数应该说$this->conn
而不是$this->$conn
。