{"id":168727,"date":"2024-11-06T15:37:27","date_gmt":"2024-11-06T07:37:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/168727\/"},"modified":"2024-11-06T15:37:27","modified_gmt":"2024-11-06T07:37:27","slug":"thinkphp-%e5%af%a6%e7%8f%be%e5%be%aa%e7%92%b0%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c-thinkphp-%e5%be%aa%e7%92%b0%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/168727\/","title":{"rendered":"ThinkPHP \u5be6\u73fe\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u64cd\u4f5c (thinkphp \u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"thinkphp-%e5%af%a6%e7%8f%be%e5%be%aa%e7%92%b0%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c-pDuzXwYKse\">ThinkPHP \u5be6\u73fe\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u64cd\u4f5c<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u61c9\u7528\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u64cd\u4f5c\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u7279\u5225\u662f\u5728\u4f7f\u7528 PHP \u6846\u67b6\u5982 ThinkPHP \u6642\uff0c\u958b\u767c\u8005\u7d93\u5e38\u9700\u8981\u9032\u884c\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u7684\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728 ThinkPHP \u4e2d\u5be6\u73fe\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u7684\u64cd\u4f5c\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%be%aa%e7%92%b0%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%ef%bc%9f-pDuzXwYKse\">\u4ec0\u9ebc\u662f\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u64cd\u4f5c\uff1f<\/h2>\n<p>\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u64cd\u4f5c\u662f\u6307\u5728\u4e00\u500b\u5faa\u74b0\u4e2d\u5c0d\u6578\u64da\u5eab\u4e2d\u7684\u591a\u689d\u8a18\u9304\u9032\u884c\u66f4\u65b0\u3002\u9019\u7a2e\u64cd\u4f5c\u901a\u5e38\u7528\u65bc\u9700\u8981\u6279\u91cf\u66f4\u65b0\u6578\u64da\u7684\u60c5\u6cc1\uff0c\u4f8b\u5982\u6839\u64da\u67d0\u4e9b\u689d\u4ef6\u66f4\u65b0\u7528\u6236\u7684\u72c0\u614b\u3001\u4fee\u6539\u7522\u54c1\u7684\u50f9\u683c\u7b49\u3002<\/p>\n<h2 id=\"thinkphp-%e7%92%b0%e5%a2%83%e8%a8%ad%e7%bd%ae-pDuzXwYKse\">ThinkPHP \u74b0\u5883\u8a2d\u7f6e<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u60a8\u5df2\u7d93\u5b89\u88dd\u4e86 ThinkPHP \u6846\u67b6\u4e26\u914d\u7f6e\u597d\u6578\u64da\u5eab\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u6578\u64da\u5eab\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nreturn [\n    'db' =&gt; [\n        'type'     =&gt; 'mysql',\n        'hostname' =&gt; 'localhost',\n        'database' =&gt; 'your_database',\n        'username' =&gt; 'your_username',\n        'password' =&gt; 'your_password',\n        'hostport' =&gt; '3306',\n        'charset'  =&gt; 'utf8',\n        'prefix'   =&gt; 'tp_',\n    ],\n];\n<\/code><\/pre>\n<h2 id=\"%e5%be%aa%e7%92%b0%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%ad%a5%e9%a9%9f-pDuzXwYKse\">\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f<\/h2>\n<p>\u5728 ThinkPHP \u4e2d\u5be6\u73fe\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u7372\u53d6\u9700\u8981\u66f4\u65b0\u7684\u6578\u64da\u3002<\/li>\n<li>\u904d\u6b77\u6578\u64da\u4e26\u9032\u884c\u66f4\u65b0\u64cd\u4f5c\u3002<\/li>\n<li>\u63d0\u4ea4\u66f4\u65b0\u3002<\/li>\n<\/ol>\n<h3 id=\"%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a2%bc-pDuzXwYKse\">\u793a\u4f8b\u4ee3\u78bc<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728 ThinkPHP \u4e2d\u5be6\u73fe\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u64cd\u4f5c\uff1a<\/p>\n<pre><code>\nnamespace appindexcontroller;\n\nuse thinkController;\nuse thinkDb;\n\nclass UpdateController extends Controller\n{\n    public function updateData()\n    {\n        \/\/ \u7372\u53d6\u9700\u8981\u66f4\u65b0\u7684\u6578\u64da\n        $dataList = Db::table('tp_users')-&gt;where('status', 0)-&gt;select();\n\n        \/\/ \u904d\u6b77\u6578\u64da\u4e26\u9032\u884c\u66f4\u65b0\n        foreach ($dataList as $data) {\n            \/\/ \u5047\u8a2d\u6211\u5011\u8981\u5c07\u6240\u6709\u72c0\u614b\u70ba 0 \u7684\u7528\u6236\u66f4\u65b0\u70ba 1\n            Db::table('tp_users')-&gt;where('id', $data['id'])-&gt;update(['status' =&gt; 1]);\n        }\n\n        return '\u6578\u64da\u66f4\u65b0\u5b8c\u6210';\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-pDuzXwYKse\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u9032\u884c\u5faa\u74b0\u66f4\u65b0\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u7279\u5225\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u554f\u984c\uff1a<\/strong>\u5982\u679c\u9700\u8981\u66f4\u65b0\u7684\u6578\u64da\u91cf\u5f88\u5927\uff0c\u5efa\u8b70\u4f7f\u7528\u6279\u91cf\u66f4\u65b0\u7684\u65b9\u6cd5\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li><strong>\u4e8b\u52d9\u8655\u7406\uff1a<\/strong>\u5728\u9032\u884c\u591a\u689d\u6578\u64da\u66f4\u65b0\u6642\uff0c\u5efa\u8b70\u4f7f\u7528\u4e8b\u52d9\u4f86\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u3002<\/li>\n<li><strong>\u932f\u8aa4\u8655\u7406\uff1a<\/strong>\u5728\u66f4\u65b0\u904e\u7a0b\u4e2d\uff0c\u61c9\u8a72\u8003\u616e\u5230\u53ef\u80fd\u51fa\u73fe\u7684\u932f\u8aa4\uff0c\u4e26\u9032\u884c\u76f8\u61c9\u7684\u8655\u7406\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-pDuzXwYKse\">\u7d50\u8ad6<\/h2>\n<p>\u5728 ThinkPHP \u4e2d\u5be6\u73fe\u5faa\u74b0\u66f4\u65b0\u6578\u64da\u5eab\u64cd\u4f5c\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\uff0c\u53ea\u9700\u9075\u5faa\u57fa\u672c\u7684\u6b65\u9a5f\u4e26\u6ce8\u610f\u6027\u80fd\u548c\u932f\u8aa4\u8655\u7406\u5373\u53ef\u3002\u901a\u904e\u672c\u6587\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u8f15\u9b06\u5730\u5728\u81ea\u5df1\u7684\u9805\u76ee\u4e2d\u5be6\u73fe\u9019\u4e00\u529f\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684 ThinkPHP \u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u7a69\u5b9a\u7684\u670d\u52d9\u548c\u9748\u6d3b\u7684\u914d\u7f6e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to implement loop-based database updates in ThinkPHP for efficient data management and seamless application performance.<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-168727","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=168727"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168727\/revisions"}],"predecessor-version":[{"id":168728,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168727\/revisions\/168728"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=168727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=168727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=168727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}