{"id":48996,"date":"2024-12-02T15:39:27","date_gmt":"2024-12-02T07:39:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48996\/"},"modified":"2024-12-02T15:39:27","modified_gmt":"2024-12-02T07:39:27","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-php-%e4%bb%8e-mysql-%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%ad%e8%8e%b7%e5%8f%96%e5%90%8d%e5%8d%95%e5%b9%b6%e5%b0%86%e5%85%b6%e6%98%be%e7%a4%ba%e5%88%b0%e5%89%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48996\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241106\/1730862046672adbdecb4db.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4ece mysql \u663e\u793a\u540d\u5355\u5230\u524d\u7aef\u7684 php \u5b9e\u73b0<\/strong><\/p>\n<p>\u8981\u4ece mysql \u6570\u636e\u5e93\u4e2d\u5c06\u540d\u5355\u6570\u636e\u663e\u793a\u5230\u524d\u7aef\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/p>\n<p>\u4f7f\u7528 mysql_connect() \u51fd\u6570\u8fde\u63a5\u5230 mysql \u6570\u636e\u5e93\uff0c\u5e76\u9009\u62e9\u8981\u4ece\u4e2d\u83b7\u53d6\u6570\u636e\u7684\u6570\u636e\u5e93\u3002<\/p>\n<p><strong>2. \u6267\u884c\u67e5\u8be2<\/strong><\/p>\n<p>\u4f7f\u7528 mysql_query() \u51fd\u6570\u6267\u884c\u67e5\u8be2\u4ee5\u83b7\u53d6\u540d\u5355\u6570\u636e\u3002\u6b64\u67e5\u8be2\u5e94\u9009\u62e9\u6240\u9700\u7684\u5b57\u6bb5\u548c\u8868\u3002<\/p>\n<p><strong>3. \u904d\u5386\u7ed3\u679c<\/strong><\/p>\n<p>\u4f7f\u7528 mysql_fetch_row() \u51fd\u6570\u904d\u5386\u67e5\u8be2\u7ed3\u679c\u5e76\u9010\u884c\u63d0\u53d6\u6570\u636e\u3002<\/p>\n<p><strong>4. \u8f93\u51fa\u6570\u636e\u5230\u524d\u7aef<\/strong><\/p>\n<p>\u5728\u904d\u5386\u67e5\u8be2\u7ed3\u679c\u65f6\uff0c\u4f7f\u7528 html \u8868\u683c\u6216\u5176\u4ed6\u9002\u5f53\u7684\u683c\u5f0f\u5c06\u6570\u636e\u8f93\u51fa\u5230\u524d\u7aef\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u52a8\u6001\u521b\u5efa\u4ee5\u4e0b html\uff1a<\/p>\n<pre>&lt;table&gt;\n  &lt;tr&gt;\n    &lt;td&gt;id&lt;\/td&gt;\n    &lt;td&gt;\u59d3\u540d&lt;\/td&gt;\n    &lt;td&gt;\u5730\u5740&lt;\/td&gt;\n  &lt;\/tr&gt;\n  &lt;tr&gt;\n    &lt;td&gt;1&lt;\/td&gt;\n    &lt;td&gt;john smith&lt;\/td&gt;\n    &lt;td&gt;123 main street&lt;\/td&gt;\n  &lt;\/tr&gt;\n  &lt;tr&gt;\n    &lt;td&gt;2&lt;\/td&gt;\n    &lt;td&gt;jane doe&lt;\/td&gt;\n    &lt;td&gt;456 elm street&lt;\/td&gt;\n  &lt;\/tr&gt;\n&lt;\/table&gt;<\/pre>\n<p><strong>5. \u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u4f7f\u7528 mysql_close() \u51fd\u6570\u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528 php \u4ece mysql \u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1a<\/p>\n<pre>header(\"Content-type: text\/html; charset=utf-8\");\n$link = mysql_connect(\"localhost\", \"root\", \"\");\n\nif (!$link) {\n  echo \"\u8fde\u63a5\u5931\u8d25\uff01\";\n} else {\n  echo \"\u8fde\u63a5\u6210\u529f\uff01\";\n}\n\nmysql_select_db(\"infosystem\", $link);\n\n$q = \"SELECT * FROM info\";\nmysql_query(\"SET NAMES GB2312\");\n$rs = mysql_query($q, $link);\n\nif (!$rs) {\n  die(\"\u65e0\u6548\u7ed3\u679c\uff01\");\n}\n\necho \"&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;\";\n\nmysql_close($link);<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\u300a\u5982\u4f55\u4f7f\u7528 PHP \u4ece MySQL \u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u540d\u5355\u5e76\u5c06\u5176\u663e\u793a\u5230\u524d\u7aef\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01 \u4ece mysql \u663e\u793a\u540d\u5355\u5230\u524d\u7aef\u7684 php \u5b9e\u73b0 \u8981\u4ece mysql \u6570\u636e\u5e93\u4e2d\u5c06\u540d\u5355\u6570\u636e\u663e\u793a\u5230\u524d\u7aef\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5 \u4f7f\u7528 mysql_connect() \u51fd\u6570\u8fde\u63a5\u5230 mysql \u6570\u636e\u5e93\uff0c\u5e76\u9009\u62e9\u8981\u4ece\u4e2d\u83b7\u53d6\u6570\u636e\u7684\u6570\u636e\u5e93\u3002 2. \u6267\u884c\u67e5\u8be2 \u4f7f\u7528 mysql_query() \u51fd\u6570\u6267\u884c\u67e5\u8be2\u4ee5\u83b7\u53d6\u540d\u5355\u6570\u636e\u3002\u6b64\u67e5\u8be2\u5e94\u9009\u62e9\u6240\u9700\u7684\u5b57\u6bb5\u548c\u8868\u3002 3. \u904d\u5386\u7ed3\u679c \u4f7f\u7528 mysql_fetch_row() \u51fd\u6570\u904d\u5386\u67e5\u8be2\u7ed3\u679c\u5e76\u9010\u884c\u63d0\u53d6\u6570\u636e\u3002 4. \u8f93\u51fa\u6570\u636e\u5230\u524d\u7aef \u5728\u904d\u5386\u67e5\u8be2\u7ed3\u679c\u65f6\uff0c\u4f7f\u7528 html \u8868\u683c\u6216\u5176\u4ed6\u9002\u5f53\u7684\u683c\u5f0f\u5c06\u6570\u636e\u8f93\u51fa\u5230\u524d\u7aef\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u52a8\u6001\u521b\u5efa\u4ee5\u4e0b html\uff1a &lt;table&gt; &lt;tr&gt; &lt;td&gt;id&lt;\/td&gt; &lt;td&gt;\u59d3\u540d&lt;\/td&gt; &lt;td&gt;\u5730\u5740&lt;\/td&gt; &lt;\/tr&gt; &lt;tr&gt; &lt;td&gt;1&lt;\/td&gt; &lt;td&gt;john smith&lt;\/td&gt; &lt;td&gt;123 main street&lt;\/td&gt; &lt;\/tr&gt; [&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-48996","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48996","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=48996"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48996\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}