{"id":785,"date":"2024-11-07T11:45:41","date_gmt":"2024-11-07T03:45:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/785\/"},"modified":"2024-11-07T11:45:41","modified_gmt":"2024-11-07T03:45:41","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-php-%e8%84%9a%e6%9c%ac%e4%b8%ad%e5%af%bc%e5%85%a5-config-php-%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/785\/","title":{"rendered":"\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f"},"content":{"rendered":"<p>php \u4e2d\u7684 include() \u51fd\u6570\u5c06\u6307\u5b9a\u6587\u4ef6\u4e2d\u7684\u4ee3\u7801\u590d\u5236\u5230\u4f7f\u7528 include \u8bed\u53e5\u7684\u6587\u4ef6\u4e2d\u3002\u5b83\u6307\u793a\u9884\u5904\u7406\u5668\u5c06\u6307\u5b9a\u6587\u4ef6\u7684\u5185\u5bb9\u63d2\u5165\u5230\u5f53\u524d\u7a0b\u5e8f\u4e2d\u3002\u8981\u5305\u542b\u7684\u6587\u4ef6\u540d\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u3002\u6700\u597d\u7684\u505a\u6cd5\u662f\u5728\u540d\u4e3a\u201cconfig.php\u201d\u7684\u6587\u4ef6\u4e2d\u5199\u5165\u57fa\u672c\u6570\u636e\u5e93\u548c\u7528\u6237\u8be6\u7ec6\u4fe1\u606f\u3002\u60a8\u8fd8\u53ef\u4ee5\u5728\u201cconfig.php\u201d\u6587\u4ef6\u4e2d\u5305\u542b\u8fde\u63a5\u6784\u5efa\u8bed\u53e5\uff0c\u4ee5\u81ea\u52a8\u4e3a\u5305\u542b\u201cconfig.php\u201d\u7684\u6bcf\u4e2a\u9875\u9762\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5\u3002\u901a\u8fc7\u5305\u542b\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u53ef\u7531\u7f51\u7ad9\u7684\u591a\u4e2a\u9875\u9762\u91cd\u590d\u4f7f\u7528\u7684\u4ee3\u7801\u6a21\u677f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1119\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/1728963919720359.png\" width=\"1177\" height=\"690\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/1728963919720359.png 1177w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/1728963919720359-300x176.png 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/1728963919720359-1024x600.png 1024w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/1728963919720359-768x450.png 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/1728963919720359-670x393.png 670w\" sizes=\"auto, (max-width: 1177px) 100vw, 1177px\" title=\"\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f\u63d2\u56fe\" \/><\/p>\n<h3>\u8bed\u6cd5<\/h3>\n<pre>&lt;?php\n    include('config.php');\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u793a\u4f8b 1\uff1a\u6b64\u663e\u793a config.php \u6587\u4ef6\u7684\u521b\u5efa\u548c\u5305\u542b\u3002<\/p>\n<p>\u4ee3\u7801 1\uff1a\u521b\u5efa PHP \u6587\u4ef6\u5e76\u4ee5\u540d\u79f0\u201cconfig.php\u201d\u4fdd\u5b58\u3002<\/p>\n<pre>&lt;?php\n$host = \"localhost\";\n$database = \"GeeksForGeeks\";\n$username = \"admin\";\n$password = \"\";\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee3\u7801 2\uff1a\u521b\u5efaPHP \u6587\u4ef6\u5e76\u5c06\u5176\u4ee5\u540d\u79f0\u201ctry.php\u201d\u4fdd\u5b58\u5728\u4e0e\u201cconfig.php\u201d\u6587\u4ef6\u76f8\u540c\u7684\u6587\u4ef6\u5939\u4e2d\u3002\u590d\u5236\u4ee5\u4e0b\u4ee3\u7801\u4ee5\u5305\u542b\u201cconfig.php\u201d\u6587\u4ef6\u5e76\u6253\u5370\u6570\u636e\u5e93\u540d\u79f0\u548c\u7528\u6237\u540d\u3002<\/p>\n<pre>&lt;?php\ninclude \"config.php\";\necho \"Host: \" . $host . \" Database: \" . $database;\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1120\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437020844.png\" width=\"736\" height=\"297\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437020844.png 736w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437020844-300x121.png 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437020844-670x270.png 670w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" title=\"\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f\u63d2\u56fe1\" alt=\"\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f\u63d2\u56fe1\" \/><\/p>\n<p>\u793a\u4f8b 2\uff1a\u5982\u679c\u60a8\u60f3\u5c06 config.php \u6587\u4ef6\u7684\u5185\u5bb9\u4fdd\u5b58\u5230\u53d8\u91cf\u4e2d\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u3002<\/p>\n<p>\u4ee3\u7801 1\uff1a\u53ea\u9700\u8fd4\u56de\u201cconfig.php\u201d\u6587\u4ef6\u7684\u5185\u5bb9.<\/p>\n<pre>&lt;?php\nreturn [\n    \"host\" =&gt; \"localhost2\",\n    \"database\" =&gt; \"GeeksForGeeks2\",\n    \"username\" =&gt; \"admin\",\n    \"password\" =&gt; \"\",];\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee3\u7801 2\uff1a\u63a5\u53d7\u53d8\u91cf\u4e2d\u7684\u8fd4\u56de\u6570\u7ec4\u3002<\/p>\n<pre>&lt;?php\n$details = include \"config.php\";\necho \"Host: \" . $details[\"host\"] . \n      \" Database: \" . $details[\"database\"];\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1121\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437111804.png\" width=\"736\" height=\"297\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437111804.png 736w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437111804-300x121.png 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172896437111804-670x270.png 670w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" title=\"\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f\u63d2\u56fe2\" alt=\"\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f\u63d2\u56fe2\" \/><\/p>\n<p>\u60f3\u6210\u4e3a\u4e00\u540d\u8f6f\u4ef6\u5f00\u53d1\u4eba\u5458\u6216\u4e00\u540d\u5e0c\u671b\u63d0\u9ad8\u8f6f\u4ef6\u5f00\u53d1\u6280\u80fd\u7684\u4e13\u4e1a\u4eba\u58eb\u5417\uff1f\u7136\u540e\uff0c\u638c\u63e1\u5168\u6808\u5f00\u53d1\u7684\u6982\u5ff5\u3002\u6211\u4eec\u7684\u5168\u6808\u5f00\u53d1 &#8211; React \u548c Node.js \u8bfe\u7a0b\u5c06\u5e2e\u52a9\u60a8\u5feb\u901f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002\u901a\u8fc7\u5b9e\u8df5\u9879\u76ee\u548c\u5b9e\u9645\u793a\u4f8b\u5b66\u4e60\u4ece\u524d\u7aef\u5230\u540e\u7aef\u5f00\u53d1\u7684\u6240\u6709\u5185\u5bb9\u3002\u672c\u8bfe\u7a0b\u4f7f\u60a8\u80fd\u591f\u6784\u5efa\u51fa\u8272\u7684\u53ef\u6269\u5c55\u3001\u9ad8\u6548\u3001\u52a8\u6001\u7684 Web \u5e94\u7528\u7a0b\u5e8f\u3002\u51c6\u5907\u597d\u6210\u4e3a\u5168\u6808\u4e13\u5bb6\u4e86\u5417\uff1f\u7acb\u5373\u62a5\u540d\uff0c\u5f00\u59cb\u521b\u9020\u672a\u6765\uff01<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cPHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 PHP \u811a\u672c\u4e2d\u5bfc\u5165 config.php \u6587\u4ef6\uff1f\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>php \u4e2d\u7684 include() \u51fd\u6570\u5c06\u6307\u5b9a\u6587\u4ef6\u4e2d\u7684\u4ee3\u7801\u590d\u5236\u5230\u4f7f\u7528 include \u8bed\u53e5\u7684\u6587\u4ef6\u4e2d\u3002\u5b83\u6307\u793a\u9884\u5904\u7406\u5668\u5c06\u6307\u5b9a\u6587\u4ef6\u7684\u5185\u5bb9\u63d2\u5165\u5230\u5f53\u524d\u7a0b\u5e8f\u4e2d\u3002\u8981\u5305\u542b\u7684\u6587\u4ef6\u540d\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u3002\u6700\u597d\u7684\u505a\u6cd5\u662f\u5728\u540d\u4e3a\u201cconfig.php\u201d\u7684\u6587\u4ef6\u4e2d\u5199\u5165\u57fa\u672c\u6570\u636e\u5e93\u548c\u7528\u6237\u8be6\u7ec6\u4fe1\u606f\u3002\u60a8\u8fd8\u53ef\u4ee5\u5728\u201cconfig.php\u201d\u6587\u4ef6\u4e2d\u5305\u542b\u8fde\u63a5\u6784\u5efa\u8bed\u53e5\uff0c\u4ee5\u81ea\u52a8\u4e3a\u5305\u542b\u201cconfig.php\u201d\u7684\u6bcf\u4e2a\u9875\u9762\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5\u3002\u901a\u8fc7\u5305\u542b\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u53ef\u7531\u7f51\u7ad9\u7684\u591a\u4e2a\u9875\u9762\u91cd\u590d\u4f7f\u7528\u7684\u4ee3\u7801\u6a21\u677f\u3002 \u8bed\u6cd5 &lt;?php include(&#8216;config.php&#8217;); ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b 1\uff1a\u6b64\u663e\u793a config.php \u6587\u4ef6\u7684\u521b\u5efa\u548c\u5305\u542b\u3002 \u4ee3\u7801 1\uff1a\u521b\u5efa PHP \u6587\u4ef6\u5e76\u4ee5\u540d\u79f0\u201cconfig.php\u201d\u4fdd\u5b58\u3002 &lt;?php $host = &#8220;localhost&#8221;; $database = &#8220;GeeksForGeeks&#8221;; $username = &#8220;admin&#8221;; $password = &#8220;&#8221;; ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u4ee3\u7801 2\uff1a\u521b\u5efaPHP \u6587\u4ef6\u5e76\u5c06\u5176\u4ee5\u540d\u79f0\u201ctry.php\u201d\u4fdd\u5b58\u5728\u4e0e\u201cconfig.php\u201d\u6587\u4ef6\u76f8\u540c\u7684\u6587\u4ef6\u5939\u4e2d\u3002\u590d\u5236\u4ee5\u4e0b\u4ee3\u7801\u4ee5\u5305\u542b\u201cconfig.php\u201d\u6587\u4ef6\u5e76\u6253\u5370\u6570\u636e\u5e93\u540d\u79f0\u548c\u7528\u6237\u540d\u3002 &lt;?php include &#8220;config.php&#8221;; echo &#8220;Host: &#8221; . $host . &#8221; Database: &#8221; . $database; ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\uff1a \u793a\u4f8b [&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-785","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/785","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=785"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/785\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}