top-think / think-orm

Think ORM——the PHP Database&ORM Framework
Apache License 2.0
417 stars 175 forks source link

插入数据时,出现:Illegal offset type报错 #602

Closed liuwave closed 3 months ago

liuwave commented 3 months ago

环境:

"name": "topthink/framework",
            "version": "v8.0.4",
"name": "topthink/think-orm",
            "version": "v3.0.19",

业务代码:

Db::name('captcha')->insert([
                'key'         => $key,
                'code'        => $code,
                'captcha'     => strtoupper(implode('', $captcha)),
                'create_time' => $nowTime,
                'expire_time' => $nowTime + $this->expire
            ]);

表结构:

CREATE TABLE `ba_captcha` (
  `key` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '验证码Key',
  `code` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '验证码(加密后)',
  `captcha` text COLLATE utf8mb4_unicode_ci COMMENT '验证码数据',
  `create_time` bigint unsigned DEFAULT NULL COMMENT '创建时间',
  `expire_time` bigint unsigned DEFAULT NULL COMMENT '过期时间',
  PRIMARY KEY (`key`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='验证码表'
;

报错:

{
    "code": 0,
    "message": "Illegal offset type",
    "traces": [
        {
            "name": "TypeError",
            "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-orm\/src\/db\/PDOConnection.php",
            "line": 1774,
            "code": 0,
            "message": "Illegal offset type",
            "trace": [
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-orm\/src\/db\/PDOConnection.php",
                    "line": 1758,
                    "function": "autoInsIDType",
                    "class": "think\\db\\PDOConnection",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-orm\/src\/db\/PDOConnection.php",
                    "line": 999,
                    "function": "getLastInsID",
                    "class": "think\\db\\PDOConnection",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-orm\/src\/db\/BaseQuery.php",
                    "line": 1166,
                    "function": "insert",
                    "class": "think\\db\\PDOConnection",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/extend\/ba\/ClickCaptcha.php",
                    "line": 160,
                    "function": "insert",
                    "class": "think\\db\\BaseQuery",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/app\/api\/controller\/Common.php",
                    "line": 42,
                    "function": "creat",
                    "class": "ba\\ClickCaptcha",
                    "type": "->"
                },
                {
                    "function": "clickCaptcha",
                    "class": "app\\api\\controller\\Common",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Container.php",
                    "line": 345,
                    "function": "invokeArgs",
                    "class": "ReflectionMethod",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/route\/dispatch\/Controller.php",
                    "line": 110,
                    "function": "invokeReflectMethod",
                    "class": "think\\Container",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 59,
                    "function": "think\\route\\dispatch\\{closure}",
                    "class": "think\\route\\dispatch\\Controller",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 66,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/route\/dispatch\/Controller.php",
                    "line": 113,
                    "function": "then",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/route\/Dispatch.php",
                    "line": 52,
                    "function": "exec",
                    "class": "think\\route\\dispatch\\Controller",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Route.php",
                    "line": 755,
                    "function": "run",
                    "class": "think\\route\\Dispatch",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 59,
                    "function": "think\\{closure}",
                    "class": "think\\Route",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 66,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Route.php",
                    "line": 756,
                    "function": "then",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Http.php",
                    "line": 208,
                    "function": "dispatch",
                    "class": "think\\Route",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Http.php",
                    "line": 198,
                    "function": "dispatchToRoute",
                    "class": "think\\Http",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 59,
                    "function": "think\\{closure}",
                    "class": "think\\Http",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-multi-app\/src\/MultiApp.php",
                    "line": 51,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 59,
                    "function": "think\\app\\{closure}",
                    "class": "think\\app\\MultiApp",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/middleware\/LoadLangPack.php",
                    "line": 53,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "function": "handle",
                    "class": "think\\middleware\\LoadLangPack",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.111.cn\/vendor\/topthink\/framework\/src\/think\/Middleware.php",
                    "line": 134,
                    "function": "call_user_func"
                },
                {
                    "file": "\/www\/wwwroot\/api.111.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 85,
                    "function": "think\\{closure}",
                    "class": "think\\Middleware",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.111.cn\/app\/common\/middleware\/AllowCrossDomain.php",
                    "line": 58,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "function": "handle",
                    "class": "app\\common\\middleware\\AllowCrossDomain",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.111.cn\/vendor\/topthink\/framework\/src\/think\/Middleware.php",
                    "line": 134,
                    "function": "call_user_func"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 85,
                    "function": "think\\{closure}",
                    "class": "think\\Middleware",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.111.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 66,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-multi-app\/src\/MultiApp.php",
                    "line": 52,
                    "function": "then",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "function": "handle",
                    "class": "think\\app\\MultiApp",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Middleware.php",
                    "line": 134,
                    "function": "call_user_func"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 85,
                    "function": "think\\{closure}",
                    "class": "think\\Middleware",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-throttle\/src\/Throttle.php",
                    "line": 140,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "function": "handle",
                    "class": "think\\middleware\\Throttle",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Middleware.php",
                    "line": 134,
                    "function": "call_user_func"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 85,
                    "function": "think\\{closure}",
                    "class": "think\\Middleware",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.111.cn\/vendor\/topthink\/think-trace\/src\/TraceDebug.php",
                    "line": 71,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "function": "handle",
                    "class": "think\\trace\\TraceDebug",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Middleware.php",
                    "line": 134,
                    "function": "call_user_func"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 85,
                    "function": "think\\{closure}",
                    "class": "think\\Middleware",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Pipeline.php",
                    "line": 66,
                    "function": "think\\{closure}",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Http.php",
                    "line": 199,
                    "function": "then",
                    "class": "think\\Pipeline",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/framework\/src\/think\/Http.php",
                    "line": 162,
                    "function": "runWithRequest",
                    "class": "think\\Http",
                    "type": "->"
                },
                {
                    "file": "\/www\/wwwroot\/api.11.cn\/public\/index.php",
                    "line": 56,
                    "function": "run",
                    "class": "think\\Http",
                    "type": "->"
                }
            ],
            "source": {
                "first": 1765,
                "source": [
                    "     * @param string    $insertId 自增ID\n",
                    "     *\n",
                    "     * @return mixed\n",
                    "     *\/\n",
                    "    protected function autoInsIDType(BaseQuery $query, string $insertId)\n",
                    "    {\n",
                    "        $pk = $query->getAutoInc();\n",
                    "\n",
                    "        if ($pk) {\n",
                    "            $type = $this->getFieldsBind($query->getTable())[$pk];\n",
                    "\n",
                    "            if (self::PARAM_INT == $type) {\n",
                    "                $insertId = (int) $insertId;\n",
                    "            } elseif (self::PARAM_FLOAT == $type) {\n",
                    "                $insertId = (float) $insertId;\n",
                    "            }\n",
                    "        }\n",
                    "\n",
                    "        return $insertId;\n"
                ]
            }
        }
    ],
    "datas": [],
    "tables": {
        "GET Data": {
            "id": "6407f183-dd1c-4137-be98-cf823f255aec"
        },
        "POST Data": [],
        "Files": null,
        "Cookies": {
            "Hm_lvt_259515e4b2b97a42fd0abd4497460225": "1722480188,1722559700,1722732581,1722818565",
            "HMACCOUNT": "2E57DAE2FA8E2D79",
            "Hm_lpvt_259515e4b2b97a42fd0abd4497460225": "1722846718"
        },
        "Session": [],
        "Server\/Request Data": {
            "USER": "www",
            "HOME": "\/home\/www",
            "HTTP_COOKIE": "Hm_lvt_259515e4b2b97a42fd0abd4497460225=1722480188,1722559700,1722732581,1722818565; HMACCOUNT=2E57DAE2FA8E2D79; Hm_lpvt_259515e4b2b97a42fd0abd4497460225=1722846718",
            "HTTP_PRIORITY": "u=1, i",
            "HTTP_ACCEPT_LANGUAGE": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
            "HTTP_ACCEPT_ENCODING": "gzip, deflate, br, zstd",
            "HTTP_REFERER": "https:\/\/api.11.cn\/index.html",
            "HTTP_SEC_FETCH_DEST": "empty",
            "HTTP_SEC_FETCH_MODE": "cors",
            "HTTP_SEC_FETCH_SITE": "same-origin",
            "HTTP_SEC_CH_UA_PLATFORM": "\"Windows\"",
            "HTTP_USER_AGENT": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/125.0.0.0 Safari\/537.36 Edg\/125.0.0.0",
            "HTTP_SEC_CH_UA_MOBILE": "?0",
            "HTTP_SERVER": "true",
            "HTTP_THINK_LANG": "zh-cn",
            "HTTP_ACCEPT": "application\/json, text\/plain, *\/*",
            "HTTP_SEC_CH_UA": "\"Microsoft Edge\";v=\"125\", \"Chromium\";v=\"125\", \"Not.A\/Brand\";v=\"24\"",
            "HTTP_CACHE_CONTROL": "no-cache",
            "HTTP_PRAGMA": "no-cache",
            "HTTP_HOST": "api.11.cn",
            "PATH_INFO": "",
            "REDIRECT_STATUS": "200",
            "SERVER_NAME": "api.11.cn",
            "SERVER_PORT": "443",
            "SERVER_ADDR": "172.17.2.164",
            "REMOTE_PORT": "4449",
            "REMOTE_ADDR": "221.10.101.37",
            "SERVER_SOFTWARE": "nginx\/1.24.0",
            "GATEWAY_INTERFACE": "CGI\/1.1",
            "HTTPS": "on",
            "REQUEST_SCHEME": "https",
            "SERVER_PROTOCOL": "HTTP\/2.0",
            "DOCUMENT_ROOT": "\/www\/wwwroot\/api.1.cn\/public",
            "DOCUMENT_URI": "\/index.php",
            "REQUEST_URI": "\/api\/common\/clickCaptcha?id=6407f183-dd1c-4137-be98-cf823f255aec",
            "SCRIPT_NAME": "\/index.php",
            "CONTENT_LENGTH": "",
            "CONTENT_TYPE": "",
            "REQUEST_METHOD": "GET",
            "QUERY_STRING": "s=\/api\/common\/clickCaptcha&id=6407f183-dd1c-4137-be98-cf823f255aec",
            "SCRIPT_FILENAME": "\/www\/wwwroot\/api.11.cn\/public\/index.php",
            "FCGI_ROLE": "RESPONDER",
            "PHP_SELF": "\/index.php",
            "REQUEST_TIME_FLOAT": 1722847137.293645,
            "REQUEST_TIME": 1722847137
        }
    }
}
liuwave commented 3 months ago

\/www\/wwwroot\/api.11.cn\/vendor\/topthink\/think-orm\/src\/db\/PDOConnection.php 文件中

$pk = $query->getAutoInc(); $pk打印出来是数组

big-dream commented 3 months ago

可以先创建个 主键id字段 暂时解决该问题

big-dream commented 3 months ago

Close of #601

liuwave commented 3 months ago

额,我不该手贱更新到正式机上...

不过话说回来,你们这样发版好么?

------------------ Original ------------------ From: "top-think/think-orm" @.>; Date: Mon, Aug 5, 2024 05:51 PM @.>; @.**@.>; Subject: Re: [top-think/think-orm] 插入数据时,出现:Illegal offset type报错 (Issue #602)

Closed #602 as completed.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

big-dream commented 3 months ago

目前没有发版哈,建议不要把开发版更新到线上

liuwave commented 3 months ago

3.0.19呀

liuwave commented 3 months ago

@big-dream 我使用的是3.0.19版,不是开发版。

liuwave commented 3 months ago

希望重视一下,尽快发版修复!

liu21st commented 3 months ago

已经发版了的 这个功能之前就增加了 有问题及时反馈 也会及时修正的

hulang commented 3 months ago

@liu21st 表里没有主键,就会提示这个错误。。