嘗試將數據庫中的值與表單中傳遞的值進行匹配以檢查用戶是否存在時,出現以下錯誤。可捕捉的致命錯誤:PDoCtatement類的對象無法轉換爲字符串
Catchable fatal error: Object of class PDOStatement could not be converted to string
這是我使用的代碼:
//Check users login details
function match_login($username, $password){
//If the button has been clicked get the variables
try{
$dbh = new PDO("mysql:host=localhost;dbname=mjbox","root", "usbw");
} catch(PDOException $e) {
echo $e->getMessage();
}
$stmt = $dbh->prepare("SELECT * FROM mjbox WHERE username=? AND password=?");
$stmt->bindParam(1, $username);
$stmt->bindParam(2, $password);
$stmt->execute();
$result = mysql_query($stmt);
if(mysql_num_rows($result) > 0){
echo 'There is a match!';
}else{
echo 'nooooo';
}
}
如果你正在使用PDO,你不應該使用'mysql_ *'........ – Esailija