由於某種原因,我收到此錯誤,但我不在尋找名爲aaron
的列。Php PDO致命錯誤 - 列未找到,但我不看
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Aaron' in 'field list'' in /home/stretch045/public_html/scripts/auth.php:15 Stack trace: #0 /home/stretch045/public_html/scripts/auth.php(15): PDO->prepare('INSERT INTO use...') #1 /home/stretch045/public_html/index.php(35): Auth->checkToken('94257b73ea4ed51...') #2 {main} thrown in /home/stretch045/public_html/scripts/auth.php on line 15
CODE:
$conn = $this->db;
$stmt = $conn->prepare("UPDATE users SET rating='".$xml->rating."', atc='".$xml->ratingatc."', pilot='".$xml->ratingpilot."', division='".$xml->division."' WHERE vid='".$xml->vid."'");
$stmt->execute();
if($stmt->rowCount()==0){
$stmt = $conn->prepare("INSERT INTO users (vid, fname, lname, rating, atc, pilot, division) VALUES (".$xml->vid.",".$xml->firstname.",".$xml->lastname.",".$xml->rating.",".$xml->ratingatc.",".$xml->ratingpilot.",".$xml->division.")");
$stmt->exec($stmt);
echo 'data inserted into db';
}
在插入查詢中,沒有任何字段值包含在單引號中。 MySQL會將這些值解釋爲列名。 – 2015-07-21 00:05:07
'$ stmt-> exec($ stmt)'不是你需要在那裏做的。應該是'$ stmt-> execute()',正如Jessica在下面所建議的那樣,execute()參數應該是該語句中的一個命名參數數組,它解決了原始問題。 –