[英]how to rectify “SQLSTATE[42000]: Syntax error or access violation: 1064 ” error
Guys i'm trying to actually create a feed like facebook's feed here but i get this error that i cant figure out where im going wrong. 伙计们,我实际上是在尝试创建类似Facebook的供稿的供稿,但我收到了这个错误,我无法弄清楚我在哪里出错。 here is the code:
这是代码:
$sql3="select u.update_id, u.update_body,u.account_name,u.os_id,u.author,u.time,u.title,"
. "c.comment_body, c.os_id,c.author,c.time"
. "from updates as u, comment_update as c "
. "where c.os_id=u.update_id and u.account_name = ':session' and u.type in ('a','c') and u.account_name=':friend' and u.type =('a'|'c') order by u.time asc,c.time desc";
$stmth=$conn->prepare($sql3);
$stmth->execute(array(":session"=>$_SESSION['uname'],":friend"=>$friend));
$status_reply= $stmth->fetchAll(PDO::FETCH_ASSOC);
here is the error code:- 这是错误代码:-
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
致命错误:消息为“ SQLSTATE [42000]”的未捕获的异常“ PDOException”:语法错误或访问冲突:1064 SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as u, comment_update as c where c.os_id=u.update_id and u.account_name = ':sessi' at line 1' in /opt/lampp/htdocs/project-chg/status&comments.php:28 Stack trace: #0 /opt/lampp/htdocs/project-chg/status&comments.php(28): PDOStatement->execute(Array) #1 /opt/lampp/htdocs/project-chg/example1.php(30): include('/opt/lampp/htdo...') #2 {main} thrown in /opt/lampp/htdocs/project-chg/status&comments.php on line 28
检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在/ opt / lampp中的'as u,comment_update as c附近使用,其中c.os_id = u.update_id和u.account_name =':sessi'在第1行' /htdocs/project-chg/status&comments.php:28堆栈跟踪:#0 /opt/lampp/htdocs/project-chg/status&comments.php(28):PDOStatement-> execute(Array)#1 / opt / lampp / htdocs /project-chg/example1.php(30):include('/ opt / lampp / htdo ...')#2 {main}放在第28行的/opt/lampp/htdocs/project-chg/status&comments.php中
any help would be appreciated. 任何帮助,将不胜感激。
Your code: 您的代码:
$sql3="select u.update_id, u.update_body,u.account_name,u.os_id,u.author,u.time,u.title,"
. "c.comment_body, c.os_id,c.author,c.time"
. "from updates as u, comment_update as c "
. "where c.os_id=u.update_id and u.account_name = ':session' and u.type in ('a','c') and u.account_name=':friend' and u.type =('a'|'c') order by u.time asc,c.time desc";
Add space before from 在之前添加空间
Change ('a'|'c')
to ('a','c')
将
('a'|'c')
更改为('a','c')
Consider using JOIN
syntax instad of comma syntax 考虑使用逗号语法的
JOIN
语法instad
Probably you need to remove '
around :friend
and :session
可能您需要删除
:friend
和:session
周围的'
Whole WHERE clause conditions
are very odd for me u.account_name = :session and u.account_name=:friend
the same column??? 整个
WHERE clause conditions
对我来说很奇怪u.account_name = :session and u.account_name=:friend
在同一列上u.account_name = :session and u.account_name=:friend
??? + doubled u.type
condition +
u.type
条件加倍
Result: 结果:
$sql3="select u.update_id, u.update_body,u.account_name,u.os_id,u.author,u.time,u.title,"
. "c.comment_body, c.os_id,c.author,c.time"
. " from updates as u JOIN comment_update as c ON c.os_id=u.update_id "
. "where u.account_name = :session and u.type in ('a','c') and u.account_name=:friend and u.type =('a','c') order by u.time asc,c.time desc";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.