-1

我无法让它工作我将包括工作和我想要完成的代码。在第一个代码中它不起作用并给我一条错误消息: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;
}
4

1 回答 1

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;
    }
于 2012-11-04T06:53:52.997 回答