错误1366(HY000):错误的整数值:第1行的'id'列的'' [英] ERROR 1366 (HY000): Incorrect integer value: '' for column 'id' at row 1
本文介绍了错误1366(HY000):错误的整数值:第1行的'id'列的''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码:
$sql = "INSERT INTO ". static::$table_name ." (";
$sql .= join(", ", array_keys($attributes));
$sql .= ") VALUES ('";
$sql .= join("', '", array_values($attributes));
$sql .= "')";
输出:
echo $sql;
//INSERT INTO users (id, username, password, first_name, last_name)
VALUES ('', 'lukeduke', '123456', 'Luke', 'Duke')
运行此查询时,我得到:
When I run this query, I get:
错误1366(HY000):不正确的整数值:第1行的'id'列的
ERROR 1366 (HY000): Incorrect integer value: '' for column 'id' at row 1
推荐答案
如果要使用此插入,必须在sql中提供一个整数值而不是一个空字符串,它应该像这样:
If you want to use this insert, you must provide an integer value in your sql instead of an empty string, it should by like this:
INSERT INTO users (id, username, password, first_name, last_name)
VALUES (1, 'lukeduke', '123456', 'Luke', 'Duke')
或者如果您的ID是自动递增的,则可以使用如下所示的sql:
or if your id is autoincremental you can have your sql like this:
INSERT INTO users (username, password, first_name, last_name)
VALUES ('lukeduke', '123456', 'Luke', 'Duke')
在这种情况下,这应该是您的代码:
In this case, this should be your code:
//extracting your first element of the array (id in this case)
$attributes = array_slice($attributes, 1);
$sql = "INSERT INTO ". static::$table_name ." (";
$sql .= join(", ", array_keys($attributes));
$sql .= ") VALUES ('";
$sql .= join("', '", array_values($attributes));
$sql .= "')";
更多信息,请访问:
这篇关于错误1366(HY000):错误的整数值:第1行的'id'列的''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文