伙计们我试图在这里实际创建像facebook这样的Feed,但是我得到了这个错误,我无法弄清楚我哪里出错了。 这是代码:
$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服务器版本对应的手册,以便在'/ u,comment_update附近使用正确的语法,其中c.os_id = u.update_id和u.account_name =':sessi'在/ opt / lampp的第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 ...')#opt {lamp}抛出/ opt / lampp / htdocs / project-chg / status& ;评论.php在第28行
任何帮助将不胜感激。
答案 0 :(得分:0)
您的代码:
$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";
在
将('a'|'c')
更改为('a','c')
考虑使用逗号语法的JOIN
语法instad
您可能需要移除'
周围的:friend
和:session
整个WHERE clause conditions
对我来说很奇怪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";