gpt4 book ai didi

php - 重复 key 更新在我本地的 wordpress 中有效,但在另一个站点中无效

转载 作者:行者123 更新时间:2023-11-30 22:56:28 25 4
gpt4 key购买 nike

我创建了一个表来保存关于自定义分类法的元数据,当我使用 ON DUPLICATE KEY UPDATE 插入时,在我的 wordpress 本地实例(使用 ampps 创建)中一切正常,它发现行具有唯一键 group_id 并执行更新而不是插入。

但是,当我将此代码移动到我的开发实例(在子域上的 Internet 上运行的实例)时,ON DUPLICATE KEY UPDATE 会创建重复项。没有代码更改。

此时我被难住了。 ON DUPLICATE KEY UPDATE 有 mysql 版本限制吗?是否有插件可以在全局范围内破坏 ON DUPLICATE KEY UPDATE 的默认行为?

更新:这段代码是我用来创建表格的代码

function create_prg_team_grouping_table(){
global $wpdb;

//create the name of the table including the wordpress prefix (wp_ etc)
$search_table = $wpdb->prefix . "prg_team_grouping";
//$wpdb->show_errors();

//check if there are any tables of that name already
if($wpdb->get_var("show tables like '$search_table'") !== $search_table)
{
//create your sql
$sql = "CREATE TABLE ". $search_table . " (
stat_id mediumint(12) NOT NULL AUTO_INCREMENT,
use_in_grouping text,
group_name text,
group_id mediumint(12) NOT NULL,
group_order mediumint(9),
UNIQUE KEY (stat_id,group_id));";
}

//include the wordpress db functions
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($sql);

//register the new table with the wpdb object
if (!isset($wpdb->prg_team_grouping))
{
$wpdb->prg_team_grouping = $search_table;
//add the shortcut so you can use $wpdb->prg_team_grouping
$wpdb->tables[] = str_replace($wpdb->prefix, '', $search_table);
}
}

//add to front and backend inits
add_action('after_switch_theme', 'create_prg_team_grouping_table');

最佳答案

我会仔细检查您的索引是否是唯一的/主要的。也就是说,确保您对应该触发更新的值有唯一约束。

如果唯一的区别在于数据库,则可能是模式不完整。

MySQL INSERT IGNORE / ON DUPLICATE KEY UPDATE not detecting duplicates

关于php - 重复 key 更新在我本地的 wordpress 中有效,但在另一个站点中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26165545/

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