PDO查询语法错误

时间:2014-05-15 08:20:43

标签: mysql sql

你可以告诉我这个查询有什么问题吗?我一直在找一个小时,但我看不出任何语法错误..

$query = $database->connection->prepare(
        "SELECT 
        n.from_id AS friend_id, 
        n.type AS type,
        n.created_date AS time,
        u.user_profile_picture AS profile_picture, 
        u.user_firstname AS friend_firstname, 
        u.user_lastname AS friend_lastname, 
        FROM notifications n INNER JOIN users u ON u.user_id = n.from_id 
        WHERE n.to_id = :user_id AND n.checked = 1");   

    $query->bindValue(':user_id', $user_id, PDO::PARAM_STR); 
    $query->execute(); 

这是错误:

  

未捕获的异常' PDOException'有消息

     

' SQLSTATE [42000]:语法错误或访问冲突:1064您有   SQL语法错误;查看与您的手册相对应的手册   MySQL服务器版本,用于在' FROM附近使用正确的语法   通知n INNER JOIN用户u ON u.user_id = n.from_id WHERE   n.to_id ='在第8行'在

2 个答案:

答案 0 :(得分:3)

删除,

之前的FROM
SELECT 
        n.from_id AS friend_id, 
        n.type AS type,
        n.created_date AS time,
        u.user_profile_picture AS profile_picture, 
        u.user_firstname AS friend_firstname, 
        u.user_lastname AS friend_lastname 
        FROM notifications n INNER JOIN users u ON u.user_id = n.from_id 
        WHERE n.to_id = :user_id AND n.checked = 1

答案 1 :(得分:0)

您必须删除行尾的逗号:

u.user_lastname AS friend_lastname,