我的查询语法中出错

时间:2015-01-11 11:29:26

标签: php mysql pdo

不可否认,我暂时没有触及过MYSQL所以如果这是一个简单的错误,请原谅我。我试图使用PDO查询插入数据,但我收到此错误

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 ') VALUES ( '', '/dYtAyg4vD88hIfrR1VKDnVGhnE6.jpg', '106646', 'The'  

这是我的查询

$query = $db->prepare("INSERT INTO `cache_movies` (
        api_adult, 
        api_backdrop_path, 
        api_id, 
        api_original_title, 
        api_release_date, 
        api_poster_path, 
        api_popularity, 
        api_title, 
        api_video, 
        api_vote_average, 
        api_vote_count, 
    ) VALUES (
        :api_adult, 
        :api_backdrop_path, 
        :api_id, 
        :api_original_title, 
        :api_release_date, 
        :api_poster_path, 
        :api_popularity, 
        :api_title, 
        :api_video, 
        :api_vote_average, 
        :api_vote_count, 
    )");
$query->execute(array(
    ':api_adult' => $results['results'][0]['adult'],
    ':api_backdrop_path' => $results['results'][0]['backdrop_path'],
    ':api_id' => $results['results'][0]['id'],
    ':api_original_title' => $results['results'][0]['original_title'],
    ':api_release_date' => $results['results'][0]['release_date'],
    ':api_poster_path' => $results['results'][0]['poster_path'],
    ':api_popularity' => $results['results'][0]['popularity'],
    ':api_title' => $results['results'][0]['title'],
    ':api_video' => $results['results'][0]['video'],
    ':api_vote_average' => $results['results'][0]['vote_average'],
    ':api_vote_count' => $results['results'][0]['vote_count']
));

我使用了一个在线SQL验证器,它说错误是在) VALUES (所在的行?

2 个答案:

答案 0 :(得分:3)

删除这些行末尾的逗号:

 api_vote_count, 

:api_vote_count, 

答案 1 :(得分:2)

您必须删除这些逗号:

commas