{"id":49280,"date":"2024-12-02T08:49:44","date_gmt":"2024-12-02T00:49:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49280\/"},"modified":"2024-12-02T08:49:44","modified_gmt":"2024-12-02T00:49:44","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-php-%e5%b0%86-mysql-%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%ad%e7%9a%84%e5%90%8d%e5%8d%95%e6%98%be%e7%a4%ba%e5%88%b0%e5%89%8d%e7%ab%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49280\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300a\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241124\/17324237076742b01b298eb.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6c42\u5927\u795e\u8bb2\u89e3\u540d\u5355\u4ece mysql \u4e2d\u663e\u793a\u5230\u524d\u7aef<\/strong><\/p>\n<p>\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528 php \u4ece mysql \u6570\u636e\u5e93\u4e2d\u63d0\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5728\u524d\u7aef\u3002\u6211\u4eec\u5c06\u9010\u6b65\u5206\u89e3\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u4f7f\u4e4b\u6613\u4e8e\u7406\u89e3\u548c\u5b9e\u73b0\u3002<\/p>\n<p><strong>1. \u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5efa\u7acb\u4e0e mysql \u6570\u636e\u5e93\u7684\u8fde\u63a5\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b php \u4ee3\u7801\uff1a<\/p>\n<pre>$link = mysql_connect(\"localhost\", \"root\", \"\");<\/pre>\n<p>\u5176\u4e2d &#8220;localhost&#8221; \u662f mysql \u7684\u4e3b\u673a\u540d\uff0c&#8221;root&#8221; \u662f\u7528\u6237\u540d\uff0c\u800c &#8220;&#8221; \u662f\u5bc6\u7801\u3002<\/p>\n<p><strong>2. \u9009\u62e9\u6570\u636e\u5e93\u548c\u67e5\u8be2\u6570\u636e<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u9009\u62e9\u8981\u67e5\u8be2\u7684\u6570\u636e\u5e93\u5e76\u7f16\u5199 sql \u67e5\u8be2\u8bed\u53e5\uff1a<\/p>\n<pre>mysql_select_db(\"infosystem\", $link);\n$q = \"select * from info\";<\/pre>\n<p>\u5176\u4e2d &#8220;infosystem&#8221; \u662f\u6570\u636e\u5e93\u540d\u79f0\uff0c&#8221;info&#8221; \u662f\u8981\u67e5\u8be2\u7684\u8868\u3002<\/p>\n<p><strong>3. \u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c<\/strong><\/p>\n<p>\u6267\u884c\u67e5\u8be2\u5e76\u83b7\u53d6\u7ed3\u679c\u96c6\uff1a<\/p>\n<pre>$rs = mysql_query($q, $link);<\/pre>\n<p><strong>4. \u8bbe\u7f6e\u5b57\u7b26\u96c6<\/strong><\/p>\n<p>\u4e3a\u4e86\u5904\u7406\u4e2d\u6587\u6570\u636e\uff0c\u6211\u4eec\u9700\u8981\u8bbe\u7f6e\u5b57\u7b26\u96c6\uff1a<\/p>\n<pre>mysql_query(\"set names gb2312\");<\/pre>\n<p><strong>5. \u5faa\u73af\u7ed3\u679c\u96c6\u5e76\u663e\u793a\u6570\u636e<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u4f7f\u7528 while \u5faa\u73af\u904d\u5386\u7ed3\u679c\u96c6\uff0c\u5e76\u8f93\u51fa\u6570\u636e\uff1a<\/p>\n<pre>echo \"&lt;table&gt;\";\nwhile ($row = mysql_fetch_row($rs)) {\n    echo \"&lt;tr&gt;&lt;td&gt;$row[1]&lt;\/td&gt;&lt;td&gt;$row[2]&lt;\/td&gt;&lt;td&gt;$row[3]&lt;\/td&gt;&lt;\/tr&gt;\";\n}\necho \"&lt;\/table&gt;\";<\/pre>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u5730\u4ece mysql \u4e2d\u63d0\u53d6\u4e86\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5728\u524d\u7aef\u3002\u540e\u7eed\u8fd8\u53ef\u4ee5\u5bf9\u663e\u793a\u6837\u5f0f\u8fdb\u884c\u4f18\u5316\uff0c\u4f8b\u5982\u4f7f\u7528 css \u7f8e\u5316\u8868\u683c\u5916\u89c2\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f \u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300a\u5982\u4f55\u4f7f\u7528 PHP \u5c06 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u540d\u5355\u663e\u793a\u5230\u524d\u7aef\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b \u6c42\u5927\u795e\u8bb2\u89e3\u540d\u5355\u4ece mysql \u4e2d\u663e\u793a\u5230\u524d\u7aef \u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528 php \u4ece mysql \u6570\u636e\u5e93\u4e2d\u63d0\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5728\u524d\u7aef\u3002\u6211\u4eec\u5c06\u9010\u6b65\u5206\u89e3\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u4f7f\u4e4b\u6613\u4e8e\u7406\u89e3\u548c\u5b9e\u73b0\u3002 1. \u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5efa\u7acb\u4e0e mysql \u6570\u636e\u5e93\u7684\u8fde\u63a5\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b php \u4ee3\u7801\uff1a $link = mysql_connect(&#8220;localhost&#8221;, &#8220;root&#8221;, &#8220;&#8221;); \u5176\u4e2d &#8220;localhost&#8221; \u662f mysql \u7684\u4e3b\u673a\u540d\uff0c&#8221;root&#8221; \u662f\u7528\u6237\u540d\uff0c\u800c &#8220;&#8221; \u662f\u5bc6\u7801\u3002 2. \u9009\u62e9\u6570\u636e\u5e93\u548c\u67e5\u8be2\u6570\u636e \u63a5\u4e0b\u6765\uff0c\u9009\u62e9\u8981\u67e5\u8be2\u7684\u6570\u636e\u5e93\u5e76\u7f16\u5199 sql \u67e5\u8be2\u8bed\u53e5\uff1a mysql_select_db(&#8220;infosystem&#8221;, $link); $q = &#8220;select * from info&#8221;; \u5176\u4e2d &#8220;infosystem&#8221; \u662f\u6570\u636e\u5e93\u540d\u79f0\uff0c&#8221;info&#8221; \u662f\u8981\u67e5\u8be2\u7684\u8868\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-49280","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49280","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=49280"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49280\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}