{"id":144127,"date":"2024-11-01T08:02:23","date_gmt":"2024-11-01T00:02:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/144127\/"},"modified":"2024-11-01T08:02:24","modified_gmt":"2024-11-01T00:02:24","slug":"tp-%e6%a1%86%e6%9e%b6%e6%88%90%e5%8a%9f%e5%b1%8f%e8%94%bd%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a0%b1%e9%8c%af%ef%bc%8c%e6%8f%90%e5%8d%87%e6%87%89%e7%94%a8%e7%a9%a9%e5%ae%9a%e6%80%a7-tp-%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/144127\/","title":{"rendered":"TP \u6846\u67b6\u6210\u529f\u5c4f\u853d\u6578\u64da\u5eab\u5831\u932f\uff0c\u63d0\u5347\u61c9\u7528\u7a69\u5b9a\u6027 (tp \u6846\u67b6\u5c4f\u853d\u6578\u64da\u5eab\u5831\u932f)"},"content":{"rendered":"<h1 id=\"tp-%e6%a1%86%e6%9e%b6%e6%88%90%e5%8a%9f%e5%b1%8f%e8%94%bd%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a0%b1%e9%8c%af%ef%bc%8c%e6%8f%90%e5%8d%87%e6%87%89%e7%94%a8%e7%a9%a9%e5%ae%9a%e6%80%a7-PTCXxPRhfk\">TP \u6846\u67b6\u6210\u529f\u5c4f\u853d\u6578\u64da\u5eab\u5831\u932f\uff0c\u63d0\u5347\u61c9\u7528\u7a69\u5b9a\u6027<\/h1>\n<p>\u5728\u73fe\u4eca\u7684\u7db2\u7d61\u61c9\u7528\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u9760\u6027\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002TP \u6846\u67b6\uff08ThinkPHP\uff09\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684 PHP \u958b\u767c\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u529f\u80fd\u4f86\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7ba1\u7406\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u4e26\u6709\u6548\u5730\u8655\u7406\u932f\u8aa4\u3002\u672c\u6587\u5c07\u63a2\u8a0e TP \u6846\u67b6\u5982\u4f55\u6210\u529f\u5c4f\u853d\u6578\u64da\u5eab\u5831\u932f\uff0c\u5f9e\u800c\u63d0\u5347\u61c9\u7528\u7684\u7a69\u5b9a\u6027\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e9%8c%af%e8%aa%a4%e7%9a%84%e5%bd%b1%e9%9f%bf-PTCXxPRhfk\">\u6578\u64da\u5eab\u932f\u8aa4\u7684\u5f71\u97ff<\/h2>\n<p>\u6578\u64da\u5eab\u932f\u8aa4\u53ef\u80fd\u6703\u5c0e\u81f4\u61c9\u7528\u7a0b\u5e8f\u5d29\u6f70\u6216\u7121\u6cd5\u6b63\u5e38\u904b\u884c\uff0c\u9019\u5c0d\u7528\u6236\u9ad4\u9a57\u548c\u696d\u52d9\u904b\u71df\u90fd\u662f\u4e00\u500b\u91cd\u5927\u6311\u6230\u3002\u5e38\u898b\u7684\u6578\u64da\u5eab\u932f\u8aa4\u5305\u62ec\u9023\u63a5\u5931\u6557\u3001\u67e5\u8a62\u8a9e\u6cd5\u932f\u8aa4\u3001\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\u7b49\u3002\u9019\u4e9b\u932f\u8aa4\u4e0d\u50c5\u5f71\u97ff\u61c9\u7528\u7684\u7a69\u5b9a\u6027\uff0c\u9084\u53ef\u80fd\u5c0e\u81f4\u6578\u64da\u4e1f\u5931\u6216\u640d\u58de\u3002<\/p>\n<h2 id=\"tp-%e6%a1%86%e6%9e%b6%e7%9a%84%e9%8c%af%e8%aa%a4%e8%99%95%e7%90%86%e6%a9%9f%e5%88%b6-PTCXxPRhfk\">TP \u6846\u67b6\u7684\u932f\u8aa4\u8655\u7406\u6a5f\u5236<\/h2>\n<p>TP \u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u500b\u5f37\u5927\u7684\u932f\u8aa4\u8655\u7406\u6a5f\u5236\uff0c\u80fd\u5920\u6709\u6548\u5730\u6355\u7372\u548c\u8655\u7406\u6578\u64da\u5eab\u932f\u8aa4\u3002\u4ee5\u4e0b\u662f TP \u6846\u67b6\u4e2d\u4e00\u4e9b\u95dc\u9375\u7684\u932f\u8aa4\u8655\u7406\u529f\u80fd\uff1a<\/p>\n<ul>\n<li><strong>\u5168\u5c40\u7570\u5e38\u8655\u7406\uff1a<\/strong>TP \u6846\u67b6\u5141\u8a31\u958b\u767c\u8005\u5b9a\u7fa9\u5168\u5c40\u7570\u5e38\u8655\u7406\u5668\uff0c\u9019\u6a23\u7576\u6578\u64da\u5eab\u64cd\u4f5c\u51fa\u73fe\u932f\u8aa4\u6642\uff0c\u53ef\u4ee5\u81ea\u52d5\u6355\u7372\u4e26\u9032\u884c\u76f8\u61c9\u7684\u8655\u7406\u3002<\/li>\n<li><strong>\u65e5\u8a8c\u8a18\u9304\uff1a<\/strong>\u6846\u67b6\u652f\u6301\u5c07\u932f\u8aa4\u4fe1\u606f\u8a18\u9304\u5230\u65e5\u8a8c\u4e2d\uff0c\u65b9\u4fbf\u958b\u767c\u8005\u5f8c\u7e8c\u7684\u6392\u67e5\u548c\u5206\u6790\u3002<\/li>\n<li><strong>\u53cb\u597d\u7684\u932f\u8aa4\u63d0\u793a\uff1a<\/strong>TP \u6846\u67b6\u53ef\u4ee5\u81ea\u5b9a\u7fa9\u932f\u8aa4\u63d0\u793a\u4fe1\u606f\uff0c\u907f\u514d\u5c07\u6578\u64da\u5eab\u932f\u8aa4\u4fe1\u606f\u76f4\u63a5\u986f\u793a\u7d66\u7528\u6236\uff0c\u5f9e\u800c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ba%ab%e9%8c%af%e8%aa%a4%e5%b1%8f%e8%94%bd%e7%9a%84%e7%a4%ba%e4%be%8b-PTCXxPRhfk\">\u5be6\u73fe\u6578\u64da\u5eab\u932f\u8aa4\u5c4f\u853d\u7684\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728 TP \u6846\u67b6\u4e2d\u5be6\u73fe\u6578\u64da\u5eab\u932f\u8aa4\u7684\u5c4f\u853d\uff1a<\/p>\n<pre><code>\ntry {\n    \/\/ \u5617\u8a66\u57f7\u884c\u6578\u64da\u5eab\u67e5\u8a62\n    $result = Db::table('users')-&gt;where('id', 1)-&gt;find();\n} catch (Exception $e) {\n    \/\/ \u6355\u7372\u7570\u5e38\u4e26\u8a18\u9304\u932f\u8aa4\n    Log::error('\u6578\u64da\u5eab\u67e5\u8a62\u932f\u8aa4: ' . $e-&gt;getMessage());\n    \/\/ \u8fd4\u56de\u53cb\u597d\u7684\u932f\u8aa4\u63d0\u793a\n    return json(['status' =&gt; 'error', 'message' =&gt; '\u7cfb\u7d71\u7e41\u5fd9\uff0c\u8acb\u7a0d\u5f8c\u518d\u8a66']);\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u7576\u6578\u64da\u5eab\u67e5\u8a62\u51fa\u73fe\u932f\u8aa4\u6642\uff0c\u7cfb\u7d71\u6703\u6355\u7372\u7570\u5e38\u4e26\u8a18\u9304\u932f\u8aa4\u4fe1\u606f\uff0c\u800c\u4e0d\u6703\u5c07\u5177\u9ad4\u7684\u932f\u8aa4\u4fe1\u606f\u66b4\u9732\u7d66\u7528\u6236\u3002\u9019\u6a23\u4e0d\u50c5\u4fdd\u8b77\u4e86\u7cfb\u7d71\u7684\u5b89\u5168\u6027\uff0c\u9084\u63d0\u5347\u4e86\u61c9\u7528\u7684\u7a69\u5b9a\u6027\u3002<\/p>\n<h2 id=\"%e6%8f%90%e5%8d%87%e6%87%89%e7%94%a8%e7%a9%a9%e5%ae%9a%e6%80%a7%e7%9a%84%e5%85%b6%e4%bb%96%e6%8e%aa%e6%96%bd-PTCXxPRhfk\">\u63d0\u5347\u61c9\u7528\u7a69\u5b9a\u6027\u7684\u5176\u4ed6\u63aa\u65bd<\/h2>\n<p>\u9664\u4e86\u4f7f\u7528 TP \u6846\u67b6\u7684\u932f\u8aa4\u8655\u7406\u6a5f\u5236\u5916\uff0c\u958b\u767c\u8005\u9084\u53ef\u4ee5\u63a1\u53d6\u5176\u4ed6\u63aa\u65bd\u4f86\u9032\u4e00\u6b65\u63d0\u5347\u61c9\u7528\u7684\u7a69\u5b9a\u6027\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u5eab\u9023\u63a5\u6c60\uff1a<\/strong>\u4f7f\u7528\u6578\u64da\u5eab\u9023\u63a5\u6c60\u53ef\u4ee5\u6e1b\u5c11\u9023\u63a5\u6578\u64da\u5eab\u7684\u958b\u92b7\uff0c\u63d0\u9ad8\u61c9\u7528\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/li>\n<li><strong>\u5b9a\u671f\u5099\u4efd\u6578\u64da\uff1a<\/strong>\u5b9a\u671f\u5099\u4efd\u6578\u64da\u53ef\u4ee5\u9632\u6b62\u6578\u64da\u4e1f\u5931\uff0c\u78ba\u4fdd\u5728\u767c\u751f\u6545\u969c\u6642\u80fd\u5920\u5feb\u901f\u6062\u5fa9\u3002<\/li>\n<li><strong>\u6027\u80fd\u76e3\u63a7\uff1a<\/strong>\u5be6\u65bd\u6027\u80fd\u76e3\u63a7\u53ef\u4ee5\u53ca\u6642\u767c\u73fe\u548c\u89e3\u6c7a\u6f5b\u5728\u7684\u554f\u984c\uff0c\u5f9e\u800c\u63d0\u9ad8\u61c9\u7528\u7684\u7a69\u5b9a\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-PTCXxPRhfk\">\u7e3d\u7d50<\/h2>\n<p>TP \u6846\u67b6\u901a\u904e\u5176\u5f37\u5927\u7684\u932f\u8aa4\u8655\u7406\u6a5f\u5236\uff0c\u6210\u529f\u5c4f\u853d\u4e86\u6578\u64da\u5eab\u5831\u932f\uff0c\u5f9e\u800c\u63d0\u5347\u4e86\u61c9\u7528\u7684\u7a69\u5b9a\u6027\u3002\u958b\u767c\u8005\u53ef\u4ee5\u5229\u7528\u6846\u67b6\u63d0\u4f9b\u7684\u529f\u80fd\u4f86\u6355\u7372\u548c\u8655\u7406\u932f\u8aa4\uff0c\u4e26\u7d50\u5408\u5176\u4ed6\u7a69\u5b9a\u6027\u63d0\u5347\u63aa\u65bd\uff0c\u78ba\u4fdd\u61c9\u7528\u5728\u9762\u5c0d\u5404\u7a2e\u6311\u6230\u6642\u4f9d\u7136\u80fd\u5920\u7a69\u5b9a\u904b\u884c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\uff0c\u9019\u6a23\u53ef\u4ee5\u70ba\u61c9\u7528\u63d0\u4f9b\u7a69\u5b9a\u7684\u904b\u884c\u74b0\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TP \u6846\u67b6\u6210\u529f\u5c4f\u853d\u6578\u64da\u5eab\u5831\u932f\uff0c\u986f\u8457\u63d0\u5347\u61c9\u7528\u7a69\u5b9a\u6027\uff0c\u78ba\u4fdd\u7528\u6236\u9ad4\u9a57\u6d41\u66a2\u7121\u963b\u3002<\/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-144127","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144127","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=144127"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144127\/revisions"}],"predecessor-version":[{"id":144128,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144127\/revisions\/144128"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=144127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=144127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=144127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}