{"id":183886,"date":"2024-11-10T08:33:17","date_gmt":"2024-11-10T00:33:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/183886\/"},"modified":"2024-11-10T08:33:18","modified_gmt":"2024-11-10T00:33:18","slug":"%e4%bd%bf%e7%94%a8mysql%e5%ae%8c%e6%88%90%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e6%a0%bc%e9%81%8d%e6%ad%b7-mysql-%e9%81%8d%e6%ad%b7%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/183886\/","title":{"rendered":"\u4f7f\u7528MySQL\u5b8c\u6210\u6578\u64da\u5eab\u8868\u683c\u904d\u6b77 (mysql \u904d\u6b77\u6578\u64da\u5eab\u8868)"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8mysql%e5%ae%8c%e6%88%90%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e6%a0%bc%e9%81%8d%e6%ad%b7-RZjCWGZofT\">\u4f7f\u7528MySQL\u5b8c\u6210\u6578\u64da\u5eab\u8868\u683c\u904d\u6b77<\/h1>\n<p>\u5728\u73fe\u4ee3\u7684\u61c9\u7528\u7a0b\u5e8f\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u5df2\u7d93\u6210\u70ba\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002MySQL\u4f5c\u70ba\u4e00\u7a2e\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528MySQL\u5b8c\u6210\u6578\u64da\u5eab\u8868\u683c\u7684\u904d\u6b77\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e6%a0%bc%e9%81%8d%e6%ad%b7%ef%bc%9f-RZjCWGZofT\">\u4ec0\u9ebc\u662f\u6578\u64da\u5eab\u8868\u683c\u904d\u6b77\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u8868\u683c\u904d\u6b77\u662f\u6307\u901a\u904e\u67e5\u8a62\u6578\u64da\u5eab\u4e2d\u7684\u8868\u683c\uff0c\u7372\u53d6\u4e26\u8655\u7406\u8868\u683c\u4e2d\u7684\u6578\u64da\u3002\u9019\u4e00\u904e\u7a0b\u901a\u5e38\u6d89\u53ca\u5230\u4f7f\u7528SQL\u8a9e\u53e5\u4f86\u9078\u64c7\u3001\u904e\u6ffe\u548c\u6392\u5e8f\u6578\u64da\u3002\u904d\u6b77\u6578\u64da\u5eab\u8868\u683c\u7684\u76ee\u7684\u5728\u65bc\u63d0\u53d6\u6240\u9700\u7684\u4fe1\u606f\uff0c\u4e26\u9032\u884c\u9032\u4e00\u6b65\u7684\u6578\u64da\u8655\u7406\u6216\u5206\u6790\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8mysql%e9%80%b2%e8%a1%8c%e8%a1%a8%e6%a0%bc%e9%81%8d%e6%ad%b7%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%ad%a5%e9%a9%9f-RZjCWGZofT\">\u4f7f\u7528MySQL\u9032\u884c\u8868\u683c\u904d\u6b77\u7684\u57fa\u672c\u6b65\u9a5f<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u904d\u6b77\u6578\u64da\u5eab\u8868\u683c\u7684\u57fa\u672c\u6b65\u9a5f\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li><strong>\u9023\u63a5\u5230\u6578\u64da\u5eab\uff1a<\/strong>\u9996\u5148\uff0c\u9700\u8981\u4f7f\u7528\u9069\u7576\u7684\u6191\u8b49\u9023\u63a5\u5230MySQL\u6578\u64da\u5eab\u3002<\/li>\n<li><strong>\u57f7\u884c\u67e5\u8a62\uff1a<\/strong>\u4f7f\u7528SQL\u8a9e\u53e5\u67e5\u8a62\u6240\u9700\u7684\u6578\u64da\u3002<\/li>\n<li><strong>\u8655\u7406\u7d50\u679c\uff1a<\/strong>\u904d\u6b77\u67e5\u8a62\u7d50\u679c\uff0c\u4e26\u6839\u64da\u9700\u8981\u9032\u884c\u8655\u7406\u3002<\/li>\n<li><strong>\u95dc\u9589\u9023\u63a5\uff1a<\/strong>\u5b8c\u6210\u64cd\u4f5c\u5f8c\uff0c\u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5\u3002<\/li>\n<\/ol>\n<h2 id=\"%e7%a4%ba%e4%be%8b%ef%bc%9a%e4%bd%bf%e7%94%a8php%e9%81%8d%e6%ad%b7mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e6%a0%bc-RZjCWGZofT\">\u793a\u4f8b\uff1a\u4f7f\u7528PHP\u904d\u6b77MySQL\u6578\u64da\u5eab\u8868\u683c<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528PHP\u8a9e\u8a00\u904d\u6b77MySQL\u6578\u64da\u5eab\u8868\u683c\u7684\u7c21\u55ae\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n\/\/ 1. \u9023\u63a5\u5230\u6578\u64da\u5eab\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"database_name\";\n\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"\u9023\u63a5\u5931\u6557: \" . $conn-&gt;connect_error);\n}\n\n\/\/ 2. \u57f7\u884c\u67e5\u8a62\n$sql = \"SELECT id, name, email FROM users\";\n$result = $conn-&gt;query($sql);\n\n\/\/ 3. \u8655\u7406\u7d50\u679c\nif ($result-&gt;num_rows &gt; 0) {\n    \/\/ \u8f38\u51fa\u6bcf\u4e00\u884c\u6578\u64da\n    while($row = $result-&gt;fetch_assoc()) {\n        echo \"id: \" . $row[\"id\"]. \" - Name: \" . $row[\"name\"]. \" - Email: \" . $row[\"email\"]. \"&lt;br&gt;\";\n    }\n} else {\n    echo \"0 \u7d50\u679c\";\n}\n\n\/\/ 4. \u95dc\u9589\u9023\u63a5\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u9023\u63a5\u5230MySQL\u6578\u64da\u5eab\uff0c\u7136\u5f8c\u57f7\u884c\u4e00\u500b\u67e5\u8a62\u4ee5\u9078\u64c7\u7528\u6236\u8868\u4e2d\u7684id\u3001name\u548cemail\u5b57\u6bb5\u3002\u63a5\u8457\uff0c\u6211\u5011\u4f7f\u7528while\u5faa\u74b0\u904d\u6b77\u67e5\u8a62\u7d50\u679c\uff0c\u4e26\u8f38\u51fa\u6bcf\u4e00\u884c\u7684\u6578\u64da\u3002\u6700\u5f8c\uff0c\u6211\u5011\u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-RZjCWGZofT\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u5eab\u8868\u683c\u904d\u6b77\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8003\u616e\uff1a<\/p>\n<ul>\n<li><strong>\u5b89\u5168\u6027\uff1a<\/strong>\u78ba\u4fdd\u4f7f\u7528\u53c3\u6578\u5316\u67e5\u8a62\u4ee5\u9632\u6b62SQL\u6ce8\u5165\u653b\u64ca\u3002<\/li>\n<li><strong>\u6027\u80fd\uff1a<\/strong>\u5c0d\u65bc\u5927\u578b\u6578\u64da\u96c6\uff0c\u8003\u616e\u4f7f\u7528\u5206\u9801\u67e5\u8a62\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li><strong>\u932f\u8aa4\u8655\u7406\uff1a<\/strong>\u5728\u57f7\u884c\u67e5\u8a62\u6642\uff0c\u61c9\u8a72\u6dfb\u52a0\u932f\u8aa4\u8655\u7406\u6a5f\u5236\uff0c\u4ee5\u4fbf\u5728\u51fa\u73fe\u554f\u984c\u6642\u80fd\u5920\u53ca\u6642\u97ff\u61c9\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-RZjCWGZofT\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528MySQL\u9032\u884c\u6578\u64da\u5eab\u8868\u683c\u904d\u6b77\u662f\u4e00\u500b\u57fa\u672c\u800c\u91cd\u8981\u7684\u6280\u80fd\uff0c\u7121\u8ad6\u662f\u5728\u7db2\u7ad9\u958b\u767c\u9084\u662f\u6578\u64da\u5206\u6790\u4e2d\u90fd\u626e\u6f14\u8457\u95dc\u9375\u89d2\u8272\u3002\u901a\u904e\u6b63\u78ba\u7684\u67e5\u8a62\u548c\u6578\u64da\u8655\u7406\u65b9\u6cd5\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u53d6\u548c\u5229\u7528\u6578\u64da\u3002\u82e5\u60a8\u9700\u8981\u7a69\u5b9a\u7684\u6578\u64da\u5eab\u652f\u6301\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u4f86\u6258\u7ba1\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u548c\u9ad8\u6548\u8a2a\u554f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528MySQL\u6709\u6548\u904d\u6b77\u6578\u64da\u5eab\u8868\u683c\uff0c\u638c\u63e1\u67e5\u8a62\u6280\u5de7\u548c\u6578\u64da\u64cd\u4f5c\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u80fd\u529b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-183886","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=183886"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183886\/revisions"}],"predecessor-version":[{"id":183887,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183886\/revisions\/183887"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=183886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=183886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=183886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}