夥計們我試圖在這裏實際創建一個像Facebook的飼料這樣的飼料,但我得到這個錯誤,我不知道我哪裏會出錯。 這裏是代碼:如何糾正「SQLSTATE [42000]:語法錯誤或訪問衝突:1064」錯誤
$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);
這裏是錯誤代碼: -
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 '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
任何幫助,將不勝感激。
您需要在您的查詢 「從」 前添加一個空格。 – Thevenin
@Thevenin感謝兄弟,解決了錯誤,但現在又出現了一個新的錯誤'致命錯誤:帶有'SQLSTATE [21000]:基數違規:1241操作數應該包含1列在/ opt'的未捕獲異常'PDOException' /lampp/htdocs/project-chg/status&comments.php:28' – shan2batman