本文介紹了PDO 未捕獲異常 - 插入值列表與列列表不匹配的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我收到此異常
Uncaught exception 'PDOException' with message 'SQLSTATE[21S01]:
Insert value list does not match column list: 1136 Column count doesn't match
value count at row 1
使用此代碼:
$stmt = $conn->prepare('INSERT INTO project VALUES(:category, :title, :name)');
$stmt->execute(array(
':category' => $_POST['category'],
':title' => $_POST['title'],
':name' => $_POST['name']
));
錯誤信息是什么意思?
推薦答案
在查詢中,指定要填充的列,例如:
In your query, specify the columns that you want to populate, for example:
$stmt = $conn->prepare('INSERT INTO project (category, title, name) VALUES(:category, :title, :name)');
如果您不以這種方式指定列,則必須為表中的所有列包含一個值,這就是您收到錯誤的原因 - 因為表中還有其他列而您沒有為它們明確指定一個值.
If you don't specify the columns in that way, you have to include a value for all columns in the table, that's why you're getting the error - because there are other columns in the table and you haven't explicitly specified a value for them all.
最好指定列,因為如果將來添加任何列或更改順序,除非指定列列表,否則您的查詢將中斷.
It is better to specify the columns because if any columns are added or the order is changed in future, your query will break unless the column list is specified.
這篇關(guān)于PDO 未捕獲異常 - 插入值列表與列列表不匹配的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!