I have a query where I am counting rows but it's showing this error..
Fatal error: Uncaught exception 'PDOException' with message '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 'from=? AND to=?' at line 1' in C:\\wamp\\www\\network\\profile.php on line 38
( ! ) PDOException: 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 'from=? AND to=?' at line 1 in C:\\wamp\\www\\network\\profile.php on line 38
Here's my code :
$sql_check_friend = "SELECT COUNT(*) FROM connection_request WHERE from=:me AND";
$sql_check_friend .= "to=:friend";
$sth = $db->prepare($sql_check_friend);
$sth->bindParam(":me", $me);
$sth->bindParam(":friend", $pageuserid);
$sth->execute();
$count = $sth->fetchColumn();
if($count > 0){
echo "REQUEST SENT";
}else{
echo "NOT SENT";
}
I can't figure out what's wrong..
from
is a reserved word . It must be escaped in your query:
SELECT ... WHERE `from` := ...
^-- ^---
And ditto for to
as well - it's a reserved word too.
这是因为您的字符串/文本连接可能包含这样的引号: "
、 '
或`
。尝试删除这些引号然后执行查询,因此验证您的连接字符串。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.