gpt4 book ai didi

php - INSERT IGNORE INTO 不起作用

转载 作者:行者123 更新时间:2023-11-29 18:31:58 25 4
gpt4 key购买 nike

INSERT IGNORE INTO sobd_voucher_types(voucher_type) VALUES('$voucher_array[$i]')

我想避免插入重复数据。 voucher_type 列是唯一的。当我在 mysql 上运行这个查询时,它运行正常。但当我从 php 运行时,却没有相同的查询。重复数据仍在插入

最佳答案

如果插入重复数据,则意味着voucher_type列不唯一,因为IGNORE仅跳过错误(不防止重复插入)。

https://dev.mysql.com/doc/refman/5.7/en/insert.html

If you use the IGNORE modifier, errors that occur while executing the INSERT statement are ignored. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row is discarded and no error occurs. Ignored errors may generate warnings instead, although duplicate-key errors do not.

关于php - INSERT IGNORE INTO 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45605377/

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