我在php/mysql中遇到了我的腳本問題。這裏是由服務器顯示的錯誤:在php和mysql中的致命錯誤
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 'if exists (select * from notificacoes where uid in() order by id desc' at line 1' in C:\wamp\www\bigui\classes\Notificacoes.class.php on line 57
這裏是我的PHP代碼:
static function listar(){
$strIdAmigos = Amizade::$strIdAmigos;
$query = self::getConn()->query('select * from notificacoes where uid in ('.$strIdAmigos.') order by id desc');
return $query->fetchAll(PDO::FETCH_ASSOC);
}
我在mysql表是空的,沒有任何價值。當我插入一個值,錯誤消失,一切都很好。任何幫助?
'$ strIdAmigos'的價值是什麼?它是如何計算的?因爲這個錯誤似乎是空的。 – Mureinik
[由於在MySQL中使用保留字作爲表或列名而導致的語法錯誤]的可能重複(http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word -as-a-table-or-column-name-in-mysql) –