gpt4 book ai didi

php - NOT NULL 默认 1 同时插入 0 和 1

转载 作者:行者123 更新时间:2023-11-29 05:18:13 26 4
gpt4 key购买 nike

在 MySQL 中,我向表中添加了一个新列...

ALTER TABLE `articles` ADD `visible` NOT NULL DEFAULT (1)

我使用默认值 1 表示新文章可见,如果文章被禁用,它将更新为 0,表示无法查看。

现在,在新文章插入时,MySQL 不会按定义插入默认的 1,而是在某些行上插入 0,在其他行上插入 1。

我想知道是什么导致了这个问题以及这个问题的可能解决方案,而不是必须手动将这些行更新为 1。

插入的例子是...

INSERT INTO articles (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, news, external, nfo, lang, anon,tube, last_action) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$catid."', '" . get_date_time() . "', '".$infohash."', '".$articlesize."', '".$filecount."', ".sqlesc($fname).", '".$news."', '".$external."', '".$nfo."', '".$langid."','$anon', ".sqlesc($tube).",'".get_date_time()."')");

然后我尝试将其更新为

INSERT INTO articles (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, news, external, nfo, lang, visible, anon,tube, last_action) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$catid."', '" . get_date_time() . "', '".$infohash."', '".$articlesize."', '".$filecount."', ".sqlesc($fname).", '".$news."', '".$external."', '".$nfo."', '".$langid."','$visible', '$anon', ".sqlesc($tube).",'".get_date_time()."')");

$visible = 1;

最佳答案

您忘记添加数据类型。

你可能想要这样的东西:

ALTER TABLE `articles` ADD `visible` TINYINT NOT NULL DEFAULT 1

如果这不能解决问题,则说明您在代码中的某处设置了默认值。

关于php - NOT NULL 默认 1 同时插入 0 和 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29753243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com