{"id":190134,"date":"2024-11-12T10:03:19","date_gmt":"2024-11-12T02:03:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/190134\/"},"modified":"2024-11-12T10:03:21","modified_gmt":"2024-11-12T02:03:21","slug":"%e7%b6%b2%e9%a0%81%e8%a8%aa%e5%95%8fsql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e4%ba%a4%e4%ba%92%e8%88%87%e5%ad%98%e5%84%b2-%e7%b6%b2%e9%a0%81%e8%a8%aa%e5%95%8fsql","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/190134\/","title":{"rendered":"\u7db2\u9801\u8a2a\u554fSQL\u6578\u64da\u5eab\uff0c\u5be6\u73fe\u6578\u64da\u4ea4\u4e92\u8207\u5b58\u5132 (\u7db2\u9801\u8a2a\u554fsql\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e7%b6%b2%e9%a0%81%e8%a8%aa%e5%95%8fsql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e4%ba%a4%e4%ba%92%e8%88%87%e5%ad%98%e5%84%b2-mJnayocFiy\">\u7db2\u9801\u8a2a\u554fSQL\u6578\u64da\u5eab\uff0c\u5be6\u73fe\u6578\u64da\u4ea4\u4e92\u8207\u5b58\u5132<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u5b57\u6642\u4ee3\uff0c\u7db2\u7ad9\u7684\u529f\u80fd\u4e0d\u50c5\u9650\u65bc\u5c55\u793a\u975c\u614b\u5167\u5bb9\uff0c\u9084\u9700\u8981\u80fd\u5920\u8207\u7528\u6236\u9032\u884c\u4e92\u52d5\uff0c\u4e26\u6709\u6548\u5730\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\u3002SQL\u6578\u64da\u5eab\u4f5c\u70ba\u4e00\u7a2e\u6d41\u884c\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u985e\u7db2\u7ad9\u4e2d\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u901a\u904e\u7db2\u9801\u8a2a\u554fSQL\u6578\u64da\u5eab\uff0c\u4ee5\u5be6\u73fe\u6578\u64da\u7684\u4ea4\u4e92\u8207\u5b58\u5132\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afsql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-mJnayocFiy\">\u4ec0\u9ebc\u662fSQL\u6578\u64da\u5eab\uff1f<\/h2>\n<p>SQL\uff08\u7d50\u69cb\u5316\u67e5\u8a62\u8a9e\u8a00\uff09\u6578\u64da\u5eab\u662f\u4e00\u7a2e\u4f7f\u7528SQL\u8a9e\u8a00\u4f86\u7ba1\u7406\u548c\u64cd\u4f5c\u6578\u64da\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u3002\u5b83\u5141\u8a31\u7528\u6236\u5275\u5efa\u3001\u8b80\u53d6\u3001\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u3002\u5e38\u898b\u7684SQL\u6578\u64da\u5eab\u5305\u62ecMySQL\u3001PostgreSQL\u548cMicrosoft SQL Server\u7b49\u3002\u9019\u4e9b\u6578\u64da\u5eab\u901a\u5e38\u7528\u65bc\u5b58\u5132\u7528\u6236\u4fe1\u606f\u3001\u7522\u54c1\u6578\u64da\u3001\u8a02\u55ae\u8a18\u9304\u7b49\u3002<\/p>\n<h2 id=\"%e7%b6%b2%e9%a0%81%e5%a6%82%e4%bd%95%e8%a8%aa%e5%95%8fsql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-mJnayocFiy\">\u7db2\u9801\u5982\u4f55\u8a2a\u554fSQL\u6578\u64da\u5eab\uff1f<\/h2>\n<p>\u8981\u5be6\u73fe\u7db2\u9801\u8a2a\u554fSQL\u6578\u64da\u5eab\uff0c\u901a\u5e38\u9700\u8981\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li><strong>\u8a2d\u7f6e\u6578\u64da\u5eab\uff1a<\/strong>\u9996\u5148\uff0c\u9700\u8981\u5728\u4f3a\u670d\u5668\u4e0a\u5b89\u88dd\u4e26\u914d\u7f6eSQL\u6578\u64da\u5eab\u3002\u9019\u5305\u62ec\u5275\u5efa\u6578\u64da\u5eab\u548c\u8868\u683c\uff0c\u4e26\u8a2d\u7f6e\u76f8\u61c9\u7684\u7528\u6236\u6b0a\u9650\u3002<\/li>\n<li><strong>\u5efa\u7acb\u5f8c\u7aef\u670d\u52d9\uff1a<\/strong>\u4f7f\u7528\u5f8c\u7aef\u8a9e\u8a00\uff08\u5982PHP\u3001Python\u6216Node.js\uff09\u4f86\u7de8\u5bebAPI\uff0c\u9019\u4e9bAPI\u5c07\u8655\u7406\u4f86\u81ea\u524d\u7aef\u7684\u8acb\u6c42\uff0c\u4e26\u8207\u6578\u64da\u5eab\u9032\u884c\u4ea4\u4e92\u3002<\/li>\n<li><strong>\u524d\u7aef\u8acb\u6c42\uff1a<\/strong>\u5728\u524d\u7aef\u4f7f\u7528JavaScript\uff08\u4f8b\u5982AJAX\uff09\u4f86\u767c\u9001\u8acb\u6c42\u5230\u5f8c\u7aefAPI\uff0c\u4e26\u7372\u53d6\u6578\u64da\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b%ef%bc%9a%e4%bd%bf%e7%94%a8php%e8%a8%aa%e5%95%8fmysql%e6%95%b8%e6%93%9a%e5%ba%ab-mJnayocFiy\">\u793a\u4f8b\uff1a\u4f7f\u7528PHP\u8a2a\u554fMySQL\u6578\u64da\u5eab<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528PHP\u8a2a\u554fMySQL\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>&lt;?php\n\/\/ \u6578\u64da\u5eab\u9023\u63a5\u53c3\u6578\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"database_name\";\n\n\/\/ \u5275\u5efa\u9023\u63a5\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\/\/ \u67e5\u8a62\u6578\u64da\n$sql = \"SELECT id, name FROM users\";\n$result = $conn-&gt;query($sql);\n\nif ($result-&gt;num_rows &gt; 0) {\n    \/\/ \u8f38\u51fa\u6578\u64da\n    while($row = $result-&gt;fetch_assoc()) {\n        echo \"id: \" . $row[\"id\"]. \" - Name: \" . $row[\"name\"]. \"&lt;br&gt;\";\n    }\n} else {\n    echo \"0 \u7d50\u679c\";\n}\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e6%93%9a%e4%ba%a4%e4%ba%92%e7%9a%84%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-mJnayocFiy\">\u6578\u64da\u4ea4\u4e92\u7684\u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u5728\u5be6\u73fe\u7db2\u9801\u8a2a\u554fSQL\u6578\u64da\u5eab\u7684\u904e\u7a0b\u4e2d\uff0c\u5b89\u5168\u6027\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u5b89\u5168\u63aa\u65bd\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u9810\u8655\u7406\u8a9e\u53e5\uff1a<\/strong>\u9019\u53ef\u4ee5\u9632\u6b62SQL\u6ce8\u5165\u653b\u64ca\uff0c\u78ba\u4fdd\u7528\u6236\u8f38\u5165\u7684\u6578\u64da\u4e0d\u6703\u5f71\u97ff\u5230SQL\u67e5\u8a62\u7684\u7d50\u69cb\u3002<\/li>\n<li><strong>\u9a57\u8b49\u7528\u6236\u8f38\u5165\uff1a<\/strong>\u5c0d\u7528\u6236\u8f38\u5165\u7684\u6578\u64da\u9032\u884c\u9a57\u8b49\u548c\u904e\u6ffe\uff0c\u4ee5\u78ba\u4fdd\u5176\u7b26\u5408\u9810\u671f\u683c\u5f0f\u3002<\/li>\n<li><strong>\u9650\u5236\u6578\u64da\u5eab\u6b0a\u9650\uff1a<\/strong>\u78ba\u4fdd\u61c9\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u6578\u64da\u5eab\u7528\u6236\u50c5\u64c1\u6709\u57f7\u884c\u5fc5\u8981\u64cd\u4f5c\u7684\u6b0a\u9650\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-mJnayocFiy\">\u7d50\u8ad6<\/h2>\n<p>\u901a\u904e\u7db2\u9801\u8a2a\u554fSQL\u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u4ea4\u4e92\u8207\u5b58\u5132\uff0c\u9019\u5c0d\u65bc\u73fe\u4ee3\u7db2\u7ad9\u7684\u904b\u884c\u81f3\u95dc\u91cd\u8981\u3002\u7121\u8ad6\u662f\u7528\u65bc\u7528\u6236\u7ba1\u7406\u3001\u7522\u54c1\u5c55\u793a\u9084\u662f\u6578\u64da\u5206\u6790\uff0cSQL\u6578\u64da\u5eab\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u548c\u53ef\u9760\u7684\u652f\u6301\u3002\u70ba\u4e86\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\uff0c\u958b\u767c\u8005\u61c9\u8a72\u9075\u5faa\u6700\u4f73\u5be6\u8e10\uff0c\u4e26\u5b9a\u671f\u6aa2\u67e5\u548c\u66f4\u65b0\u7cfb\u7d71\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u7db2\u7ad9\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>\uff0c\u4ee5\u78ba\u4fdd\u60a8\u7684\u6578\u64da\u5eab\u80fd\u5920\u7a69\u5b9a\u904b\u884c\u4e26\u5feb\u901f\u97ff\u61c9\u7528\u6236\u8acb\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u901a\u904e\u7db2\u9801\u8a2a\u554fSQL\u6578\u64da\u5eab\uff0c\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u4ea4\u4e92\u8207\u5b58\u5132\uff0c\u63d0\u5347\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u8207\u7528\u6236\u9ad4\u9a57\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-190134","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190134","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=190134"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190134\/revisions"}],"predecessor-version":[{"id":190135,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190134\/revisions\/190135"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=190134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=190134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=190134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}