{"id":6881,"date":"2024-11-14T11:54:29","date_gmt":"2024-11-14T03:54:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6881\/"},"modified":"2024-11-14T11:54:29","modified_gmt":"2024-11-14T03:54:29","slug":"go-%e9%a1%b9%e7%9b%ae%e4%b8%ad-gin-%e5%92%8c-mysql-%e5%87%ba%e7%8e%b0-invalid-memory-address-or-nil-pointer-dereference-%e9%94%99%e8%af%af%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6881\/","title":{"rendered":"Go \u9879\u76ee\u4e2d Gin \u548c MySQL \u51fa\u73b0 \u201cinvalid memory address or nil pointer dereference\u201d \u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3 Stmt \u5f15\u7528\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173000665376470.jpg\" class=\"aligncenter\" title=\"Go \u9879\u76ee\u4e2d Gin \u548c MySQL \u51fa\u73b0 \u201cinvalid memory address or nil pointer dereference\u201d \u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3 Stmt \u5f15\u7528\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"Go \u9879\u76ee\u4e2d Gin \u548c MySQL \u51fa\u73b0 \u201cinvalid memory address or nil pointer dereference\u201d \u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3 Stmt \u5f15\u7528\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>go \u9879\u76ee\u4e2d gin \u548c  \u51fa\u73b0\u9519\u8bef<\/strong><\/p>\n<p>\u4f60\u5728\u4f7f\u7528 \u3001gin \u548c mysql \u65f6\u9047\u5230\u4e86\u4e00\u4e2a\u9519\u8bef\uff0c\u9519\u8bef\u4fe1\u606f\u4e3a\uff1a<\/p>\n<pre>invalid memory address or nil pointer dereference<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u4f60\u4f7f\u7528 mysql \u8fde\u63a5\u6c60\u4e2d\u7684 stmt \u51fa\u73b0\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4f60\u5728\u8fde\u63a5\u6c60\u4e2d\u4f7f\u7528 stmt \u65f6\uff0c\u9700\u8981\u5728\u4f7f\u7528\u5b8c\u6210\u540e\u5173\u95ed\u5b83\u3002\u4f46\u662f\uff0c\u4f60\u53ef\u80fd\u5728\u4f7f\u7528 stmt \u540e\u4ecd\u7136\u6301\u6709\u5b83\u7684\u5f15\u7528\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u4f7f\u7528\u7684\u662f stmt.exec \u65b9\u6cd5\uff0c\u800c\u4e0d\u662f stmt.execcontext \u65b9\u6cd5\u3002stmt.execcontext \u65b9\u6cd5\u4f1a\u63a5\u53d7\u4e00\u4e2a context \u53c2\u6570\uff0c\u5b83\u4f1a\u5728\u4e0a\u4e0b\u6587\u88ab\u53d6\u6d88\u6216\u8d85\u65f6\u65f6\u81ea\u52a8\u5173\u95ed stmt\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u63a8\u8350\u4f60\u4f7f\u7528 stmt.execcontext \u65b9\u6cd5\uff0c\u5e76\u786e\u4fdd\u5728\u4f7f\u7528\u5b8c stmt \u540e\u7acb\u5373\u5173\u95ed\u5b83\u3002\u8fd9\u53ef\u4ee5\u907f\u514d\u51fa\u73b0\u6307\u5411\u5df2\u5173\u95ed stmt \u7684\u65e0\u6548\u5f15\u7528\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fGo \u9879\u76ee\u4e2d Gin \u548c MySQL \u51fa\u73b0 \u201cinvalid memory address or nil pointer dereference\u201d \u9519\u8bef\uff1a\u5982\u4f55\u89e3\u51b3 Stmt \u5f15\u7528\u95ee\u9898\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>go \u9879\u76ee\u4e2d gin \u548c \u51fa\u73b0\u9519\u8bef \u4f60\u5728\u4f7f\u7528 \u3001gin \u548c mysql \u65f6\u9047\u5230\u4e86\u4e00\u4e2a\u9519\u8bef\uff0c\u9519\u8bef\u4fe1\u606f\u4e3a\uff1a invalid memory address or nil pointer dereference \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u4f60\u4f7f\u7528 mysql \u8fde\u63a5\u6c60\u4e2d\u7684 stmt \u51fa\u73b0\u7684\u95ee\u9898\u3002 \u4f60\u5728\u8fde\u63a5\u6c60\u4e2d\u4f7f\u7528 stmt \u65f6\uff0c\u9700\u8981\u5728\u4f7f\u7528\u5b8c\u6210\u540e\u5173\u95ed\u5b83\u3002\u4f46\u662f\uff0c\u4f60\u53ef\u80fd\u5728\u4f7f\u7528 stmt \u540e\u4ecd\u7136\u6301\u6709\u5b83\u7684\u5f15\u7528\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u4f7f\u7528\u7684\u662f stmt.exec \u65b9\u6cd5\uff0c\u800c\u4e0d\u662f stmt.execcontext \u65b9\u6cd5\u3002stmt.execcontext \u65b9\u6cd5\u4f1a\u63a5\u53d7\u4e00\u4e2a context \u53c2\u6570\uff0c\u5b83\u4f1a\u5728\u4e0a\u4e0b\u6587\u88ab\u53d6\u6d88\u6216\u8d85\u65f6\u65f6\u81ea\u52a8\u5173\u95ed stmt\u3002 \u56e0\u6b64\uff0c\u63a8\u8350\u4f60\u4f7f\u7528 stmt.execcontext \u65b9\u6cd5\uff0c\u5e76\u786e\u4fdd\u5728\u4f7f\u7528\u5b8c stmt \u540e\u7acb\u5373\u5173\u95ed\u5b83\u3002\u8fd9\u53ef\u4ee5\u907f\u514d\u51fa\u73b0\u6307\u5411\u5df2\u5173\u95ed stmt \u7684\u65e0\u6548\u5f15\u7528\u3002 \u4ee5\u4e0a\u5c31\u662fGo \u9879\u76ee\u4e2d Gin \u548c MySQL \u51fa\u73b0 \u201cinvalid memory address or nil [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6881","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6881"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6881\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}