{"id":431658,"date":"2024-12-17T13:20:31","date_gmt":"2024-12-17T05:20:31","guid":{"rendered":"https:\/\/www.idc.net\/help\/431658\/"},"modified":"2024-12-17T13:20:32","modified_gmt":"2024-12-17T05:20:32","slug":"%e6%97%a0%e9%99%90mysql%e6%95%b0%e6%8d%ae%e5%ba%93%ef%bc%8cphp%e7%a9%ba%e9%97%b4%e8%b6%85%e5%bc%ba%e5%85%bc%e5%ae%b9%e6%80%a7","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/431658\/","title":{"rendered":"\u65e0\u9650Mysql\u6570\u636e\u5e93\uff0cphp\u7a7a\u95f4\u8d85\u5f3a\u517c\u5bb9\u6027"},"content":{"rendered":"<h1 id=\"%e6%97%a0%e9%99%90mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%8ephp%e7%a9%ba%e9%97%b4%e8%b6%85%e5%bc%ba%e5%85%bc%e5%ae%b9%e6%80%a7-IWQkdSMwSz\">\u65e0\u9650Mysql\u6570\u636e\u5e93\u4e0ePHP\u7a7a\u95f4\u8d85\u5f3a\u517c\u5bb9\u6027<\/h1>\n<p>\u5728\u5f53\u4eca\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u6570\u636e\u5e93\u548c\u7f16\u7a0b\u8bed\u8a00\u7684\u9009\u62e9\u5bf9\u7f51\u7ad9\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u81f3\u5173\u91cd\u8981\u3002Mysql\u4f5c\u4e3a\u4e00\u79cd\u6d41\u884c\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u56e0\u5176\u9ad8\u6548\u3001\u7075\u6d3b\u548c\u5f00\u6e90\u7684\u7279\u6027\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u7f51\u7ad9\u548c\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u800cPHP\u4f5c\u4e3a\u4e00\u79cd\u670d\u52a1\u5668\u7aef\u811a\u672c\u8bed\u8a00\uff0c\u56e0\u5176\u4e0eMysql\u7684\u826f\u597d\u517c\u5bb9\u6027\uff0c\u6210\u4e3a\u4e86\u5f00\u53d1\u52a8\u6001\u7f51\u7ad9\u7684\u9996\u9009\u8bed\u8a00\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u65e0\u9650Mysql\u6570\u636e\u5e93\u7684\u4f18\u52bf\u4ee5\u53caPHP\u7a7a\u95f4\u7684\u8d85\u5f3a\u517c\u5bb9\u6027\u3002<\/p>\n<h2 id=\"%e6%97%a0%e9%99%90mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e4%bc%98%e5%8a%bf-IWQkdSMwSz\">\u65e0\u9650Mysql\u6570\u636e\u5e93\u7684\u4f18\u52bf<\/h2>\n<p>\u65e0\u9650Mysql\u6570\u636e\u5e93\u7684\u6982\u5ff5\u662f\u6307\u5728\u670d\u52a1\u5668\u4e0a\u63d0\u4f9b\u4e0d\u53d7\u9650\u5236\u7684Mysql\u6570\u636e\u5e93\u4f7f\u7528\u3002\u8fd9\u79cd\u670d\u52a1\u5bf9\u4e8e\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u4f01\u4e1a\u548c\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u5177\u6709\u663e\u8457\u7684\u4f18\u52bf\uff1a<\/p>\n<ul>\n<li><strong>\u7075\u6d3b\u6027\uff1a<\/strong>\u65e0\u9650Mysql\u6570\u636e\u5e93\u5141\u8bb8\u7528\u6237\u6839\u636e\u9700\u6c42\u521b\u5efa\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u9002\u5e94\u4e0d\u540c\u9879\u76ee\u7684\u9700\u6c42\u3002<\/li>\n<li><strong>\u9ad8\u53ef\u7528\u6027\uff1a<\/strong>\u901a\u8fc7\u8d1f\u8f7d\u5747\u8861\u548c\u6570\u636e\u5907\u4efd\uff0c\u786e\u4fdd\u6570\u636e\u5e93\u7684\u9ad8\u53ef\u7528\u6027\uff0c\u51cf\u5c11\u5b95\u673a\u65f6\u95f4\u3002<\/li>\n<li><strong>\u6613\u4e8e\u6269\u5c55\uff1a<\/strong>\u968f\u7740\u4e1a\u52a1\u7684\u53d1\u5c55\uff0c\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u6269\u5c55\u6570\u636e\u5e93\u7684\u5b58\u50a8\u7a7a\u95f4\u548c\u6027\u80fd\u3002<\/li>\n<li><strong>\u6210\u672c\u6548\u76ca\uff1a<\/strong>\u5bf9\u4e8e\u4e2d\u5c0f\u578b\u4f01\u4e1a\u6765\u8bf4\uff0c\u65e0\u9650\u6570\u636e\u5e93\u7684\u5b9a\u4ef7\u6a21\u5f0f\u901a\u5e38\u6bd4\u6309\u9700\u4ed8\u8d39\u66f4\u5177\u6210\u672c\u6548\u76ca\u3002<\/li>\n<\/ul>\n<h2 id=\"php%e4%b8%8emysql%e7%9a%84%e5%85%bc%e5%ae%b9%e6%80%a7-IWQkdSMwSz\">PHP\u4e0eMysql\u7684\u517c\u5bb9\u6027<\/h2>\n<p>PHP\u4e0eMysql\u7684\u7ed3\u5408\u4f7f\u5f97\u5f00\u53d1\u52a8\u6001\u7f51\u7ad9\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u548c\u9ad8\u6548\u3002\u4ee5\u4e0b\u662fPHP\u4e0eMysql\u517c\u5bb9\u6027\u7684\u4e00\u4e9b\u5173\u952e\u70b9\uff1a<\/p>\n<ul>\n<li><strong>\u7b80\u5355\u6613\u7528\uff1a<\/strong>PHP\u63d0\u4f9b\u4e86\u591a\u79cd\u5185\u7f6e\u51fd\u6570\u6765\u4e0eMysql\u6570\u636e\u5e93\u8fdb\u884c\u4ea4\u4e92\uff0c\u4f8b\u5982\u8fde\u63a5\u6570\u636e\u5e93\u3001\u6267\u884c\u67e5\u8be2\u7b49\u3002<\/li>\n<li><strong>\u9ad8\u6548\u6027\u80fd\uff1a<\/strong>PHP\u4e0eMysql\u7684\u7ed3\u5408\u80fd\u591f\u5feb\u901f\u5904\u7406\u5927\u91cf\u6570\u636e\u8bf7\u6c42\uff0c\u9002\u5408\u9ad8\u6d41\u91cf\u7f51\u7ad9\u3002<\/li>\n<li><strong>\u5b89\u5168\u6027\uff1a<\/strong>\u901a\u8fc7\u4f7f\u7528\u9884\u5904\u7406\u8bed\u53e5\u548c\u53c2\u6570\u7ed1\u5b9a\uff0cPHP\u53ef\u4ee5\u6709\u6548\u9632\u6b62SQL\u6ce8\u5165\u653b\u51fb\uff0c\u589e\u5f3a\u6570\u636e\u5e93\u7684\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u5e7f\u6cdb\u652f\u6301\uff1a<\/strong>\u51e0\u4e4e\u6240\u6709\u7684\u4e3b\u673a\u670d\u52a1\u90fd\u652f\u6301PHP\u548cMysql\u7684\u7ec4\u5408\uff0c\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u627e\u5230\u5408\u9002\u7684\u6258\u7ba1\u670d\u52a1\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81-IWQkdSMwSz\">\u793a\u4f8b\u4ee3\u7801<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684PHP\u4ee3\u7801\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u8fde\u63a5Mysql\u6570\u636e\u5e93\u5e76\u6267\u884c\u67e5\u8be2\uff1a<\/p>\n<pre><code>\nconnect_error) {\n    die(\"\u8fde\u63a5\u5931\u8d25: \" . $conn-&gt;connect_error);\n}\n\n\/\/ \u6267\u884c\u67e5\u8be2\n$sql = \"SELECT id, name FROM users\";\n$result = $conn-&gt;query($sql);\n\nif ($result-&gt;num_rows &gt; 0) {\n    \/\/ \u8f93\u51fa\u6570\u636e\n    while($row = $result-&gt;fetch_assoc()) {\n        echo \"id: \" . $row[\"id\"]. \" - Name: \" . $row[\"name\"]. \"<br>\";\n    }\n} else {\n    echo \"0 \u7ed3\u679c\";\n}\n$conn-&gt;close();\n?&gt;\n<\/code><\/pre>\n<h2 id=\"%e6%80%bb%e7%bb%93-IWQkdSMwSz\">\u603b\u7ed3<\/h2>\n<p>\u65e0\u9650Mysql\u6570\u636e\u5e93\u548cPHP\u7684\u8d85\u5f3a\u517c\u5bb9\u6027\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5e2e\u52a9\u4ed6\u4eec\u6784\u5efa\u9ad8\u6548\u3001\u7075\u6d3b\u548c\u5b89\u5168\u7684\u7f51\u7ad9\u3002\u65e0\u8bba\u662f\u4e2d\u5c0f\u578b\u4f01\u4e1a\u8fd8\u662f\u5927\u578b\u4f01\u4e1a\uff0c\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u5e93\u548c\u7f16\u7a0b\u8bed\u8a00\u90fd\u662f\u6210\u529f\u7684\u5173\u952e\u3002\u540e\u6d6a\u4e91\u63d0\u4f9b\u7684<a href=\"https:\/\/idc.net\">\u4e91\u670d\u52a1\u5668<\/a>\u548c<a href=\"https:\/\/idc.net\">VPS<\/a>\u89e3\u51b3\u65b9\u6848\uff0c\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u7528\u6237\u7684\u9700\u6c42\uff0c\u52a9\u529b\u4f01\u4e1a\u5728\u6570\u5b57\u5316\u8f6c\u578b\u4e2d\u53d6\u5f97\u6210\u529f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e0\u9650Mysql\u6570\u636e\u5e93\u4e0ePHP\u7a7a\u95f4\u5b8c\u7f8e\u517c\u5bb9\uff0c\u63d0\u4f9b\u5f3a\u5927\u6027\u80fd\u4e0e\u7075\u6d3b\u6027\uff0c\u52a9\u529b\u7f51\u7ad9\u5feb\u901f\u53d1\u5c55\u4e0e\u9ad8\u6548\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[202759],"tags":[],"class_list":["post-431658","post","type-post","status-publish","format-standard","hentry","category-webhosting"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/431658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=431658"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/431658\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=431658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=431658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=431658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}