簡體   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