1

我有以下函数,它总是返回 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;
        }
    }

}
4

1 回答 1

1

你没有检查错误,试试这个:

if($stmt->execute()) {
 //code
}
else{
 die($stmt->error);
}

或者:

if($stmt = $this->conn->prepare($query)){
 //code
}
else{
 die($this->conn->error);
}
于 2009-03-15T20:31:56.157 回答