我以前曾經遇到過這個問題,並且無法爲我的生活弄清楚導致它的原因。我有一個PDO聲明,看起來像這樣PDO在我的MySQL語句中途拋出一個未捕獲的異常
$fields = "
`ProgramName` = :programName,
`TotalUnits` = :totalUnits,
`UnitCost` = :unitCost,
`Description` = :description,
`CreationDate` = NOW()
";
$description = isset($_POST['description']) ? $_POST['description'] : null;
$insertProgram = $dbHandle -> prepare("INERT INTO `Programs` SET $fields");
$insertProgram -> bindParam(':programName', $_POST['programName']);
$insertProgram -> bindParam(':totalUnits' , $_POST['totalUnits'] );
$insertProgram -> bindParam(':unitCost' , $_POST['unitCost'] );
$insertProgram -> bindParam(':description', $description );
$insertProgram -> execute();
的錯誤是一般的老「
語法錯誤或訪問衝突:1064 ...檢查手冊正確的語法附近使用。
`ProgramName` =?,
`TotalUnits` =? ,
'統一」在行1
看到它切斷 「UnitCost」,甚至認爲這是在$領域完全格式化字符串?世界上是什麼導致了這一點?我在我的所有專欄名稱上使用反撥號...
'INERT'可能無助於事情。 –
同意@JonStirling。上面的代碼會在'INERT'上引發一個語法錯誤,所以爲了在這裏發佈一個最簡單的例子,你已經明確地改變了你的代碼(謝謝),但是這些簡化也可能掩蓋了你的底層錯誤,把'INERT'改爲'INSERT'不應該產生你引用的錯誤。 – eggyal
好吧,那肯定是問題(我有多愚蠢)。所以現在對於真正的問題,爲什麼錯誤信息是如此模糊?在我的田野中途停下來讓我覺得我有些隱形的字符串在某種程度上......(@eggyal,因爲事實證明這是錯誤。哈哈哈,但我重申了我的上述問題。爲什麼MySql,爲什麼?) –