我有以下功能,它总是返回false。它甚至没有尝试执行该语句,我知道因为我更改了$ query =“aldfjaf lkjfsk”并且它没有为我返回错误。有什么建议吗?
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 user_table
WHERE login_username = ? AND login_password = ?";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param('ss', $un, $pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
答案 0 :(得分:1)
您没有检查错误,请尝试以下操作:
if($stmt->execute()) {
//code
}
else{
die($stmt->error);
}
或:
if($stmt = $this->conn->prepare($query)){
//code
}
else{
die($this->conn->error);
}