You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建my-aac游戏角色遇SQL唯一键重复错误,求禁用日志方法

角色创建时SQL重复条目错误及错误日志禁用需求

错误信息

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '91230-101' for key 'player_id_2'

错误堆栈

Backtrace:

#0 C:\xampp\htdocs\system\libs\pot\OTS_Base_DB.php(86): PDO->query('INSERT INTO `pl...')
#1 C:\xampp\htdocs\system\libs\pot\OTS_DB_PDOQuery.php(13): OTS_Base_DB->doQuery('INSERT INTO `pl...')
#2 C:\xampp\htdocs\system\libs\CreateCharacter.php(258): OTS_Base_DB->query('INSERT INTO `pl...')
#3 C:\xampp\htdocs\system\pages\account\create_character.php(25): CreateCharacter->doCreate('Testwebpage', 1, 0, 32, Object(OTS_Account), Array)
#4 C:\xampp\htdocs\system\pages\accountmanagement.php(145): require('C:\\xampp\\htdocs...')
#5 C:\xampp\htdocs\index.php(347): require('C:\\xampp\\htdocs...')
#6 {main}

相关代码片段

OTS_Base_DB.php(86)

$ret = parent::query(...$args);

完整方法代码:

private function doQuery(...$args)
{
    $this->queries++;

    if($this->logged) {
        $startTime = microtime(true);
    }

    $ret = parent::query(...$args);
    if($this->logged) {
        $totalTime = microtime(true) - $startTime;
        $this->log .= round($totalTime, 4) . ' ms - ' . $args[0] . PHP_EOL;
    }

    return $ret;
}

OTS_DB_PDOQuery.php(13)

return $this->doQuery(...func_get_args());

完整文件代码:

<?php

if (PHP_VERSION_ID >= 80000) {
    require LIBS . 'pot/OTS_DB_PDOQuery_PHP71.php';
} else {
    trait OTS_DB_PDOQuery
    {
        /**
         * @return PDOStatement
         */
        public function query()
        {
            return $this->doQuery(...func_get_args());
        }
    }
}

CreateCharacter.php(258)

$db->query("INSERT INTO `player_items` (`player_id` ,`pid` ,`sid` ,`itemtype`, `count`, `attributes`) VALUES ('".$player->getId()."', '".$save_item['pid']."', '".$save_item['sid']."', '".$save_item['itemtype']."', '".$save_item['count']."', $blob);");

相关循环代码:

$loaded_items_to_copy = $db->query("SELECT * FROM player_items WHERE player_id = ".$char_to_copy->getId()."");
foreach($loaded_items_to_copy as $save_item) {
    $blob = $db->quote($save_item['attributes']);
    $db->query("INSERT INTO `player_items` (`player_id` ,`pid` ,`sid` ,`itemtype`, `count`, `attributes`) VALUES ('".$player->getId()."', '".$save_item['pid']."', '".$save_item['sid']."', '".$save_item['itemtype']."', '".$save_item['count']."', $blob);");
}

create_character.php(25)

$character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $account_logged, $errors);

相关逻辑代码:

if($save) {
    require_once LIBS . 'CreateCharacter.php';
    $createCharacter = new CreateCharacter();

    $character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $account_logged, $errors);
}

accountmanagement.php(145)

require PAGES . 'account/' . $action . '.php';

相关逻辑代码:

else if(file_exists(PAGES . 'account/' . $action . '.php')) {
    require PAGES . 'account/' . $action . '.php';
}

index.php(347)

require $file;

相关逻辑代码:

if($hooks->trigger(HOOK_BEFORE_PAGE)) {
    if(!$ignore)
        require $file;
}

补充说明

  • 每次创建新角色都会触发类似重复条目错误,错误条目格式如91231-101、91232-101
  • 当前数据库为非空库,角色实际已成功创建并生成新ID,但创建流程末尾仍会弹出该错误
  • 数据库索引截图:
    数据库索引截图

问题

是否可以禁用该错误日志?

内容的提问来源于stack exchange,提问作者D3rL0wen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 21:10:28