PDO Uncaught exception - Insert value list does not match column list(PDO 未捕获异常 - 插入值列表与列列表不匹配)
问题描述
我收到此异常
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.
这篇关于PDO 未捕获异常 - 插入值列表与列列表不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PDO 未捕获异常 - 插入值列表与列列表不匹配


- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01