[英]Sql error in Cakephp2 FindBy statement, getting a 1064 syntax error
[英]sql statement error on getting rows and
我有像彩票的游戏。 通常,当用户注册代码时,该代码是唯一的,数据库应检查该代码是否存在,是否存在应更新注册用户并获得消息“您的代码已注册” ...每个代码只能注册一次。 但我总是收到一条错误消息,提示我每次尝试注册一个代码时都说“您的代码不存在,但是代码在银行。
function checkCode($db,$code){
$stmt = $db->prepare("INSERT INTO code (code) VALUES (:code)");
$stmt->bindParam(':code', $codex);
$codex = $code;
$stmt->execute();
//enter code here
///// until here is ok
$sql = "SELECT * FROM code";
$result = $db->prepare($sql);
$result->execute();
////here is what i think generate the error
$number_of_rows = $result->rowCount();
if($number_of_rows >0){
return true;
} else{
return false;
}
}
http://php.net/manual/en/pdostatement.rowcount.php
rowCount
获取受影响的行数。 SELECT
语句不影响任何行。 您应该在rowCount
中检查$stmt
,而不是$result
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.