SQL错误,但我看不出有什么问题

时间:2014-10-24 15:03:01

标签: php mysql sql

我有一个非常简单的查询:

SELECT like__id FROM like WHERE like__snap__id = :like__snap__id

我在这个PHP代码中使用此查询:

try {
    $select_like_query = 'SELECT like__id FROM like WHERE like__snap__id = :like__snap__id';
    $prep_select_like = $conn->prepare($select_like_query);
    $prep_select_like->bindParam(':like__snap__id', $snap__id, PDO::PARAM_INT);
    $prep_select_like->execute();
    $like_result = $prep_select_like->fetchAll();
    $like_count = count($like_result);
}   
catch(PDOException $e) {
    $conn = null;
    echo $error;
}

这引发了一个异常,它说:

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 'like WHERE like__snap__id = '3'' at line 1' in C:\xampp\htdocs\snapll_back\snap\me_snaps.php:78 Stack trace: #0 C:\xampp\htdocs\snapll_back\snap\me_snaps.php(78): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\snapll_back\snap\me_snaps.php on line 78

这是一个如此简单的查询,我这样查询了一百次,我不明白出了什么问题。我认为我的SQL语法看起来很好。

0 个答案:

没有答案