MYSQL - 空字符串== 0问题(使用主键0更新行而不是插入)
实际上这已经起作用了,我不知道我改变了什么,所以我现在遇到了这个问题。几乎尝试了一切。
案例:
我有以下查询。如果我要保存的内容是新的,则变量 $DB-id 是空字符串。 module_id 字段是我的主键。发生的情况是,此查询始终更新带有 module_id => 的行。 0.
问题
传递空变量作为主键始终会更新第 0 行,而不是插入新行。
$this->db->query("INSERT INTO modules_text
(
module_id,
module_content,
module_page_idx,
module_post_id
)
VALUES (
'{$DB_id}',
'{$content['text']}',
'{$content['idx']}',
'{$post_id}'
)
ON DUPLICATE KEY
UPDATE module_content = '{$content['text']}',
module_page_idx = '{$content['idx']}'
");
有人知道我如何告诉 MYSQL 创建一个新行吗???非常感谢任何帮助!非常感谢!!!
萨卢多斯萨沙!
actually this already worked and i have no idea what i've changed so that i run into this problem now. Tried nearly everything.
The case:
I have the following query. The variable $DB-id is an empty string if the content i want to save is new. The field module_id is my primary key. What happens is that this query always updates the row with the module_id => 0.
The problem
Passing an empty variable as the primary key always updates row 0 instead of inserting a new one.
$this->db->query("INSERT INTO modules_text
(
module_id,
module_content,
module_page_idx,
module_post_id
)
VALUES (
'{$DB_id}',
'{$content['text']}',
'{$content['idx']}',
'{$post_id}'
)
ON DUPLICATE KEY
UPDATE module_content = '{$content['text']}',
module_page_idx = '{$content['idx']}'
");
Does anybody have an idea how i can tell MYSQL to create a new row??? Any help is very appreciated!!!! Thank you very much!!!
Saludos Sacha!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要将主键字段设置为自动增量。下面是一个例子。
You may need to set your primary key field to auto increment. An example is below.