在mysqli中插入ID为自动增量的数据的正确方法 [英] proper way of inserting data with id as auto-increment in mysqli
本文介绍了在mysqli中插入ID为自动增量的数据的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以验证使用MYSQLI插入数据的正确方法吗?
can someone please verify the proper way of inserting data using MYSQLI?
我需要将注释数据插入ID设置为自动递增的表中.我只是将id的值保留为 blank 吗?
i need to insert comment data into the table with ID set as auto-increment. do i just leave the values for id as blank ?
$db = dbConnect();
$query = "INSERT INTO comments values ('', '$comment')";
$db->query($query);
推荐答案
正确的方法是忽略值,或者为其分配NULL.
虽然在您的示例中使用的空字符串不是有效值,但在严格模式下,它将发出警告.
A proper way would be either omit value, or assign NULL to it.
While empty string which is used in your example, is not a valid value and in strict mode it will issue a warning.
INSERT INTO comments VALUES (NULL, 'comment')
INSERT INTO comments (comment) VALUES ('comment')
全部有效.
这篇关于在mysqli中插入ID为自动增量的数据的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文