我无法解决这个问题。我将把代码包括在工作和我想要完成的工作中。在第一个代码中它不起作用并给我一条错误消息:Connection failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':userName AND
密码=:userPass' at line 1
我已经尝试了几种不同的语法组合,但仍然没有运气。在第二个代码示例中,它是工作代码,基本上我试图摆脱所有不必要的代码,只是从函数中获取$row
计数,以验证有1行匹配查询。
function checkLogin($conn,$myusername, $mypassword) {
$stmt = $conn->prepare('SELECT COUNT(*) FROM `CLL_users` WHERE `user_name`= :userName AND `password`= :userPass');
$stmt->bindValue(':userName', $myusername);
$stmt->bindValue(':userPass', $mypassword);
$stmt->execute();
$count = $stmt->fetchColumn();
return $count;
}
答案 0 :(得分:0)
function checkLogin($conn,$myusername, $mypassword) {
$stmt = $conn->prepare('SELECT COUNT(*) FROM `CLL_users` WHERE `user_name`= :userName AND `password`= :userPass');
$stmt->bindValue(':userName', $myusername);
$stmt->bindValue(':userPass', $mypassword);
$stmt->execute();
$count = $stmt->fetchColumn();
return $count;
}