PDO插入错误

时间:2010-10-01 18:51:51

标签: php mysql pdo

我正在尝试让下面的代码工作.....

错误:

ERRORSQLSTATE[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 '?, ?, ?, ?)' at line 1

代码:

$data=array($idApplications,$author,$addedOn,$note);
try {
    $STH = $this->DBH->query('
      INSERT INTO '.$table.' (idApplications,Author,NoteAddedOn,Note) 
      VALUES (?, ?, ?, ?)
   ');
    $STH->execute($data);
}
catch(PDOException $e) {echo $e->getMessage();}
}   

(使用PHP PDO和MySQL)

任何帮助将不胜感激!

谢谢!

1 个答案:

答案 0 :(得分:2)

问题是你正在尝试准备一个陈述,但你正在执行它(通过query())而不是准备它。

->query(...);更改为->prepare(...);,其余部分保持原样......

PDO::Prepare()