【发布时间】:2015-11-09 14:03:28
【问题描述】:
伙计们,我正在尝试在这里创建一个类似于 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);
这是错误代码:-
致命错误:未捕获异常 'PDOException' 并带有消息 'SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法,以便在 /opt/lampp 中的 'as u, comment_update as c where c.os_id=u.update_id and u.account_name = ':sessi' at line 1' 附近使用/htdocs/project-chg/status&cmets.php:28 堆栈跟踪:#0 /opt/lampp/htdocs/project-chg/status&cmets.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&cmets.php 中抛出
任何帮助将不胜感激。
【问题讨论】:
-
您需要在查询中的“from”之前添加一个空格。
-
@Thevenin 感谢兄弟解决了错误,但现在出现了一个新错误,如下所示
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)' in /opt/lampp/htdocs/project-chg/status&comments.php:28