繁体   English   中英

如何纠正“ SQLSTATE [42000]:语法错误或访问冲突:1064”错误

[英]how to rectify “SQLSTATE[42000]: Syntax error or access violation: 1064 ” error

伙计们,我实际上是在尝试创建类似Facebook的供稿的供稿,但我收到了这个错误,我无法弄清楚我在哪里出错。 这是代码:

$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);

这是错误代码:-

致命错误:消息为“ SQLSTATE [42000]”的未捕获的异常“ PDOException”:语法错误或访问冲突:1064 SQL语法有错误; 检查与您的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中

任何帮助,将不胜感激。

您的代码:

$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";
  1. 在之前添加空间

  2. ('a'|'c')更改为('a','c')

  3. 考虑使用逗号语法的JOIN语法instad

  4. 可能您需要删除:friend:session周围的'

  5. 整个WHERE clause conditions对我来说很奇怪u.account_name = :session and u.account_name=:friend在同一列上u.account_name = :session and u.account_name=:friend ??? + u.type条件加倍

结果:

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM