我可能只是太累了,我錯過了一些非常簡單的東西,但我無法弄清楚。看起來無法找到SQL Statement錯誤的地方
試圖執行以下查詢:在此錯誤
INSERT INTO chars (charName,charClass,charLevel,charLife,charES,charInt,charStr,charDex)
VALUES (mlkauschwitz,ranger,81,4500,50,50,300,250)
ON DUPLICATE KEY UPDATE charClass=ranger,charLevel=81,charLife=4500,charES=50,charInt=50,charStr=300,charDex=250;
結果:
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'mlkauschwitz' in 'field list'"
爲什麼想的值是場?
使用以下PHP:
include "db.php";
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$char = array(
'charClass'=>'ranger',
'charDex'=>'250',
'charES'=>'50',
'charInt'=>'50',
'charLevel'=>'81',
'charLife'=>'4500',
'charName'=>'mlkauschwitz',
'charStr'=>'300',
);
$sql = 'INSERT INTO chars (charName,charClass,charLevel,charLife,charES,charInt,charStr,charDex) VALUES ('.$char["charName"].','.$char["charClass"].','.$char["charLevel"].','.$char["charLife"].','.$char["charES"].','.$char["charInt"].','.$char["charStr"].','.$char["charDex"].') ON DUPLICATE KEY UPDATE charClass='.$char["charClass"].',charLevel='.$char["charLevel"].',charLife='.$char["charLife"].',charES='.$char["charES"].',charInt='.$char["charInt"].',charStr='.$char["charStr"].',charDex='.$char["charDex"].';';
$stmt = $conn->prepare($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
if ($stmt) {
try {
$stmt->execute();
}
catch (PDOException $e) {
var_dump($e);
}
}
CHARNAME字段獨特/初級。
注意,這不會_add_引號的字符串。另外,PDO不需要PDO,因爲PDO負責引用和轉義。 – 2013-04-22 05:07:08