{"id":22303,"date":"2024-11-21T09:01:28","date_gmt":"2024-11-21T01:01:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22303\/"},"modified":"2024-11-21T09:01:28","modified_gmt":"2024-11-21T01:01:28","slug":"thinkphp%e6%80%8e%e4%b9%88%e6%9f%a5%e8%af%a2%e6%95%b0%e6%8d%ae%e5%ba%93%e8%be%93%e5%87%ba%e6%8c%87%e5%ae%9a%e5%ad%97%e6%ae%b5%e5%90%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22303\/","title":{"rendered":"thinkphp\u600e\u4e48\u67e5\u8be2\u6570\u636e\u5e93\u8f93\u51fa\u6307\u5b9a\u5b57\u6bb5\u540d"},"content":{"rendered":"<p>\u5728\u4f7f\u7528php\u8fdb\u884c\u7f51\u7ad9\u5f00\u53d1\u65f6\uff0c\u67e5\u8be2\u6570\u636e\u5e93\u662f\u975e\u5e38\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u800c\u5728\u4f7f\u7528thinkphp\u8fd9\u4e2a\u4f18\u79c0\u7684php\u5f00\u53d1\u6846\u67b6\u65f6\uff0c\u67e5\u8be2\u6570\u636e\u5e93\u4e5f\u662f\u975e\u5e38\u65b9\u4fbf\u5feb\u6377\u7684\u64cd\u4f5c\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u4f1a\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528thinkphp\u67e5\u8be2\u6570\u636e\u5e93\uff0c\u5e76\u8f93\u51fa\u6307\u5b9a\u7684\u5b57\u6bb5\u3002<\/p>\n<ol>\n<li>\u9996\u5148\u9700\u8981\u8fde\u63a5\u6570\u636e\u5e93<\/li>\n<\/ol>\n<p>\u5728ThinkPHP\u4e2d\uff0c\u8fde\u63a5\u6570\u636e\u5e93\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u5728\/config\/database.php\u6587\u4ef6\u4e2d\u914d\u7f6e\u597d\u76f8\u5e94\u7684\u6570\u636e\u5e93\u4fe1\u606f\u5373\u53ef\u3002<\/p>\n<p>\u4ee5mysql\u6570\u636e\u5e93\u4e3a\u4f8b\uff0c\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n<pre>'type'            =&gt; 'mysql',         \/\/ \u6570\u636e\u5e93\u7c7b\u578b\n'hostname'        =&gt; '127.0.0.1',     \/\/ \u670d\u52a1\u5668\u5730\u5740\n'database'        =&gt; 'test_db',       \/\/ \u6570\u636e\u5e93\u540d\n'username'        =&gt; 'test_user',     \/\/ \u7528\u6237\u540d\n'password'        =&gt; 'test_password', \/\/ \u5bc6\u7801\n'hostport'        =&gt; '3306',          \/\/ \u7aef\u53e3\u53f7<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u6784\u5efa\u67e5\u8be2\u6761\u4ef6<\/li>\n<\/ol>\n<p>\u6784\u5efa\u67e5\u8be2\u6761\u4ef6\u662f\u8fdb\u884c\u6570\u636e\u5e93\u67e5\u8be2\u7684\u7b2c\u4e00\u6b65\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u60a8\u9700\u8981\u4f7f\u7528ThinkPHP\u63d0\u4f9b\u7684Query\u5bf9\u8c61\u6765\u6784\u5efa\u67e5\u8be2\u6761\u4ef6\u3002Query\u5bf9\u8c61\u662f\u4e00\u79cd\u94fe\u5f0f\u8c03\u7528\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6781\u5927\u65b9\u4fbf\u60a8\u7684\u67e5\u8be2\u64cd\u4f5c\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u60f3\u8981\u67e5\u8be2\u7528\u6237\u8868\u4e2dage\u5927\u4e8e\u7b49\u4e8e18\u5c81\u7684\u7528\u6237\uff0c\u53ef\u4ee5\u8fd9\u6837\u6784\u5efa\u67e5\u8be2\u6761\u4ef6\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>use thinkdbQuery;\n\n$query = new Query();\n$query-&gt;table('user')\n      -&gt;where('age', '&gt;=', 18);\n$res = $query-&gt;select();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u8f93\u51fa\u6307\u5b9a\u7684\u5b57\u6bb5<\/li>\n<\/ol>\n<p>\u5728\u8fdb\u884c\u67e5\u8be2\u64cd\u4f5c\u65f6\uff0c\u5f80\u5f80\u53ea\u9700\u8981\u67d0\u4e9b\u5b57\u6bb5\u7684\u503c\uff0c\u800c\u4e0d\u9700\u8981\u6240\u6709\u5b57\u6bb5\u7684\u503c\u3002\u4e3a\u4e86\u8f93\u51fa\u6307\u5b9a\u7684\u5b57\u6bb5\uff0c\u60a8\u53ef\u4ee5\u5728\u67e5\u8be2\u64cd\u4f5c\u4e2d\u52a0\u5165field\u65b9\u6cd5\uff0c\u4f20\u5165\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5185\u90e8\u662f\u9700\u8981\u67e5\u8be2\u7684\u5b57\u6bb5\u540d\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u73b0\u5728\u9700\u8981\u67e5\u8be2\u7528\u6237\u8868\u4e2d\u6240\u670918\u5c81\u4ee5\u4e0a\u7684\u7528\u6237\u7684\u59d3\u540d\u548c\u5e74\u9f84\u3002\u53ef\u4ee5\u8fd9\u6837\u64cd\u4f5c\uff1a<\/p>\n<pre>$query-&gt;table('user')\n      -&gt;where('age', '&gt;=', 18)\n      -&gt;field('name, age');\n$res = $query-&gt;select();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\uff0c\u67e5\u8be2\u7ed3\u679c\u4e2d\u5c06\u53ea\u5305\u542b\u59d3\u540d\u548c\u5e74\u9f84\u4e24\u4e2a\u5b57\u6bb5\u7684\u503c\uff0c\u5176\u4ed6\u5b57\u6bb5\u7684\u503c\u5c06\u4e0d\u4f1a\u51fa\u73b0\u5728\u67e5\u8be2\u7ed3\u679c\u4e2d\u3002<\/p>\n<ol>\n<li>\u603b\u7ed3<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528ThinkPHP\u67e5\u8be2\u6570\u636e\u5e93\uff0c\u5e76\u8f93\u51fa\u6307\u5b9a\u5b57\u6bb5\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5feb\u901f\u8f7b\u677e\u5730\u8fdb\u884c\u6570\u636e\u5e93\u67e5\u8be2\uff0c\u5e76\u5c06\u67e5\u8be2\u7ed3\u679c\u8f93\u51fa\u4e3a\u6307\u5b9a\u7684\u5b57\u6bb5\u7684\u503c\u3002\u5982\u679c\u60a8\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8eThinkPHP\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff0c\u6216\u8005\u53c2\u52a0\u76f8\u5173\u57f9\u8bad\u8bfe\u7a0b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fthinkphp\u600e\u4e48\u67e5\u8be2\u6570\u636e\u5e93\u8f93\u51fa\u6307\u5b9a\u5b57\u6bb5\u540d\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4f7f\u7528php\u8fdb\u884c\u7f51\u7ad9\u5f00\u53d1\u65f6\uff0c\u67e5\u8be2\u6570\u636e\u5e93\u662f\u975e\u5e38\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u800c\u5728\u4f7f\u7528thinkphp\u8fd9\u4e2a\u4f18\u79c0\u7684php\u5f00\u53d1\u6846\u67b6\u65f6\uff0c\u67e5\u8be2\u6570\u636e\u5e93\u4e5f\u662f\u975e\u5e38\u65b9\u4fbf\u5feb\u6377\u7684\u64cd\u4f5c\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u4f1a\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528thinkphp\u67e5\u8be2\u6570\u636e\u5e93\uff0c\u5e76\u8f93\u51fa\u6307\u5b9a\u7684\u5b57\u6bb5\u3002 \u9996\u5148\u9700\u8981\u8fde\u63a5\u6570\u636e\u5e93 \u5728ThinkPHP\u4e2d\uff0c\u8fde\u63a5\u6570\u636e\u5e93\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u8981\u5728\/config\/database.php\u6587\u4ef6\u4e2d\u914d\u7f6e\u597d\u76f8\u5e94\u7684\u6570\u636e\u5e93\u4fe1\u606f\u5373\u53ef\u3002 \u4ee5mysql\u6570\u636e\u5e93\u4e3a\u4f8b\uff0c\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b\uff1a &#8216;type&#8217; =&gt; &#8216;mysql&#8217;, \/\/ \u6570\u636e\u5e93\u7c7b\u578b &#8216;hostname&#8217; =&gt; &#8216;127.0.0.1&#8217;, \/\/ \u670d\u52a1\u5668\u5730\u5740 &#8216;database&#8217; =&gt; &#8216;test_db&#8217;, \/\/ \u6570\u636e\u5e93\u540d &#8216;username&#8217; =&gt; &#8216;test_user&#8217;, \/\/ \u7528\u6237\u540d &#8216;password&#8217; =&gt; &#8216;test_password&#8217;, \/\/ \u5bc6\u7801 &#8216;hostport&#8217; =&gt; &#8216;3306&#8217;, \/\/ \u7aef\u53e3\u53f7 \u767b\u5f55\u540e\u590d\u5236 \u6784\u5efa\u67e5\u8be2\u6761\u4ef6 \u6784\u5efa\u67e5\u8be2\u6761\u4ef6\u662f\u8fdb\u884c\u6570\u636e\u5e93\u67e5\u8be2\u7684\u7b2c\u4e00\u6b65\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u60a8\u9700\u8981\u4f7f\u7528ThinkPHP\u63d0\u4f9b\u7684Query\u5bf9\u8c61\u6765\u6784\u5efa\u67e5\u8be2\u6761\u4ef6\u3002Query\u5bf9\u8c61\u662f\u4e00\u79cd\u94fe\u5f0f\u8c03\u7528\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6781\u5927\u65b9\u4fbf\u60a8\u7684\u67e5\u8be2\u64cd\u4f5c\u3002 \u4f8b\u5982\uff0c\u60f3\u8981\u67e5\u8be2\u7528\u6237\u8868\u4e2dage\u5927\u4e8e\u7b49\u4e8e18\u5c81\u7684\u7528\u6237\uff0c\u53ef\u4ee5\u8fd9\u6837\u6784\u5efa\u67e5\u8be2\u6761\u4ef6\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b use thinkdbQuery; $query = new Query(); $query-&gt;table(&#8216;user&#8217;) -&gt;where(&#8216;age&#8217;, &#8216;&gt;=&#8217;, 18); $res = $query-&gt;select(); \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u6307\u5b9a\u7684\u5b57\u6bb5 \u5728\u8fdb\u884c\u67e5\u8be2\u64cd\u4f5c\u65f6\uff0c\u5f80\u5f80\u53ea\u9700\u8981\u67d0\u4e9b\u5b57\u6bb5\u7684\u503c\uff0c\u800c\u4e0d\u9700\u8981\u6240\u6709\u5b57\u6bb5\u7684\u503c\u3002\u4e3a\u4e86\u8f93\u51fa\u6307\u5b9a\u7684\u5b57\u6bb5\uff0c\u60a8\u53ef\u4ee5\u5728\u67e5\u8be2\u64cd\u4f5c\u4e2d\u52a0\u5165field\u65b9\u6cd5\uff0c\u4f20\u5165\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5185\u90e8\u662f\u9700\u8981\u67e5\u8be2\u7684\u5b57\u6bb5\u540d\u3002 [&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-22303","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22303","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=22303"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22303\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}