{"id":25293,"date":"2024-11-21T15:29:25","date_gmt":"2024-11-21T07:29:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25293\/"},"modified":"2024-11-21T15:29:25","modified_gmt":"2024-11-21T07:29:25","slug":"laravel%e6%94%af%e6%8c%81%e5%87%a0%e7%a7%8d%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25293\/","title":{"rendered":"laravel\u652f\u6301\u51e0\u79cd\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  laravel \u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5305\u62ec\uff1amysql\u3001postgresql\u3001sqlite\u3001sql server\u3001mariadb\u3001mongodb \u548c redis\u3002\u8981\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u60a8\u9700\u8981\u5728 .env \u6587\u4ef6\u4e2d\u8bbe\u7f6e\u914d\u7f6e\u5e76\u4f7f\u7528 db \u5916\u89c2\u8fdb\u884c\u8fde\u63a5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040917212513701.jpg\" class=\"aligncenter\" title=\"laravel\u652f\u6301\u51e0\u79cd\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"laravel\u652f\u6301\u51e0\u79cd\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>Laravel \u652f\u6301\u7684\u6570\u636e\u5e93<\/strong><\/p>\n<p>Laravel \u662f\u4e00\u4e2a PHP \u6846\u67b6\uff0c\u5b83\u652f\u6301\u4e0e\u591a\u79cd\u6570\u636e\u5e93\u7cfb\u7edf\u8fde\u63a5\u3002<\/p>\n<p><strong>\u652f\u6301\u7684\u6570\u636e\u5e93\u7cfb\u7edf\u5305\u62ec\uff1a<\/strong><\/p>\n<ul>\n<li>MySQL<\/li>\n<li>PostgreSQL<\/li>\n<li>SQLite<\/li>\n<li>SQL Server<\/li>\n<li>MariaDB<\/li>\n<li>MongoDB<\/li>\n<li>Redis<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a<\/strong><\/p>\n<p>\u8981\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u60a8\u9700\u8981\u5728 .env \u6587\u4ef6\u4e2d\u8bbe\u7f6e\u5fc5\u8981\u7684\u914d\u7f6e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>DB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=database_name\nDB_USERNAME=username\nDB_PASSWORD=password<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528 DB \u5916\u89c2\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a<\/p>\n<pre>use IlluminateSupportFacadesDB;\n\n$users = DB::table('users')-&gt;get();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5177\u4f53\u6570\u636e\u5e93\u652f\u6301\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>MySQL\uff1a<\/strong>Laravel \u4f7f\u7528 PDO MySQL \u6269\u5c55\u4e0e MySQL \u6570\u636e\u5e93\u901a\u4fe1\u3002<\/li>\n<li> <strong>PostgreSQL\uff1a<\/strong>Laravel \u4f7f\u7528 PDO PostgreSQL \u6269\u5c55\u4e0e PostgreSQL \u6570\u636e\u5e93\u901a\u4fe1\u3002<\/li>\n<li> <strong>SQLite\uff1a<\/strong>Laravel \u4f7f\u7528 PDO SQLite \u6269\u5c55\u4e0e SQLite \u6570\u636e\u5e93\u901a\u4fe1\u3002<\/li>\n<li> <strong>SQL Server\uff1a<\/strong>Laravel \u4f7f\u7528 PDO SQL Server \u6269\u5c55\u4e0e SQL Server \u6570\u636e\u5e93\u901a\u4fe1\u3002<\/li>\n<li> <strong>MariaDB\uff1a<\/strong>MariaDB \u4e0e MySQL \u517c\u5bb9\uff0c\u56e0\u6b64\u5b83\u4f7f\u7528\u76f8\u540c\u7684\u8fde\u63a5\u65b9\u6cd5\u3002<\/li>\n<li> <strong>MongoDB\uff1a<\/strong>Laravel \u4f7f\u7528 MongoDB PHP \u5e93\u4e0e MongoDB \u6570\u636e\u5e93\u901a\u4fe1\u3002<\/li>\n<li> <strong>Redis\uff1a<\/strong>Laravel \u4f7f\u7528 P PHP \u5e93\u4e0e Redis \u6570\u636e\u5e93\u901a\u4fe1\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u652f\u6301\u51e0\u79cd\u6570\u636e\u5e93\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>laravel \u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5305\u62ec\uff1amysql\u3001postgresql\u3001sqlite\u3001sql server\u3001mariadb\u3001mongodb \u548c redis\u3002\u8981\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u60a8\u9700\u8981\u5728 .env \u6587\u4ef6\u4e2d\u8bbe\u7f6e\u914d\u7f6e\u5e76\u4f7f\u7528 db \u5916\u89c2\u8fdb\u884c\u8fde\u63a5\u3002 Laravel \u652f\u6301\u7684\u6570\u636e\u5e93 Laravel \u662f\u4e00\u4e2a PHP \u6846\u67b6\uff0c\u5b83\u652f\u6301\u4e0e\u591a\u79cd\u6570\u636e\u5e93\u7cfb\u7edf\u8fde\u63a5\u3002 \u652f\u6301\u7684\u6570\u636e\u5e93\u7cfb\u7edf\u5305\u62ec\uff1a MySQL PostgreSQL SQLite SQL Server MariaDB MongoDB Redis \u5982\u4f55\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a \u8981\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u60a8\u9700\u8981\u5728 .env \u6587\u4ef6\u4e2d\u8bbe\u7f6e\u5fc5\u8981\u7684\u914d\u7f6e\u3002\u4f8b\u5982\uff1a DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database_name DB_USERNAME=username DB_PASSWORD=password \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528 DB \u5916\u89c2\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a use IlluminateSupportFacadesDB; $users = DB::table(&#8216;users&#8217;)-&gt;get(); \u767b\u5f55\u540e\u590d\u5236 \u5177\u4f53\u6570\u636e\u5e93\u652f\u6301\uff1a MySQL\uff1aLaravel \u4f7f\u7528 PDO MySQL \u6269\u5c55\u4e0e MySQL \u6570\u636e\u5e93\u901a\u4fe1\u3002 PostgreSQL\uff1aLaravel \u4f7f\u7528 PDO [&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-25293","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25293","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=25293"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25293\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}