{"id":183362,"date":"2024-11-10T04:11:21","date_gmt":"2024-11-09T20:11:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/183362\/"},"modified":"2024-11-10T04:11:22","modified_gmt":"2024-11-09T20:11:22","slug":"%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e6%8c%81%e4%b9%85%e5%8c%96%ef%bc%9a%e6%95%b8%e7%b5%84%e5%80%bc%e5%a6%82%e4%bd%95%e5%82%b3%e5%85%a5%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-%e5%b0%87%e6%95%b8%e7%b5%84","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/183362\/","title":{"rendered":"\u5be6\u73fe\u6578\u64da\u6301\u4e45\u5316\uff1a\u6578\u7d44\u503c\u5982\u4f55\u50b3\u5165\u6578\u64da\u5eab\uff1f (\u5c07\u6578\u7d44\u7684\u503c\u50b3\u5165\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e6%8c%81%e4%b9%85%e5%8c%96%ef%bc%9a%e6%95%b8%e7%b5%84%e5%80%bc%e5%a6%82%e4%bd%95%e5%82%b3%e5%85%a5%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-pTaZSoGpXN\">\u5be6\u73fe\u6578\u64da\u6301\u4e45\u5316\uff1a\u6578\u7d44\u503c\u5982\u4f55\u50b3\u5165\u6578\u64da\u5eab\uff1f<\/h1>\n<p>\u5728\u73fe\u4ee3\u61c9\u7528\u7a0b\u5e8f\u958b\u767c\u4e2d\uff0c\u6578\u64da\u6301\u4e45\u5316\u662f\u78ba\u4fdd\u6578\u64da\u5b89\u5168\u548c\u53ef\u7528\u6027\u7684\u91cd\u8981\u904e\u7a0b\u3002\u7576\u6211\u5011\u9700\u8981\u5c07\u6578\u7d44\u4e2d\u7684\u503c\u5b58\u5132\u5230\u6578\u64da\u5eab\u4e2d\u6642\uff0c\u9019\u4e00\u904e\u7a0b\u8b8a\u5f97\u5c24\u70ba\u91cd\u8981\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5c07\u6578\u7d44\u7684\u503c\u6709\u6548\u5730\u50b3\u5165\u6578\u64da\u5eab\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e6%8c%81%e4%b9%85%e5%8c%96%e7%9a%84%e6%a6%82%e5%bf%b5-pTaZSoGpXN\">\u6578\u64da\u6301\u4e45\u5316\u7684\u6982\u5ff5<\/h2>\n<p>\u6578\u64da\u6301\u4e45\u5316\u662f\u6307\u5c07\u6578\u64da\u5f9e\u5167\u5b58\u4e2d\u4fdd\u5b58\u5230\u6301\u4e45\u5b58\u5132\u8a2d\u5099\uff08\u5982\u6578\u64da\u5eab\uff09\u4e2d\u7684\u904e\u7a0b\u3002\u9019\u6a23\u505a\u7684\u76ee\u7684\u662f\u70ba\u4e86\u5728\u61c9\u7528\u7a0b\u5e8f\u95dc\u9589\u6216\u91cd\u555f\u5f8c\uff0c\u4ecd\u7136\u80fd\u5920\u8a2a\u554f\u548c\u4f7f\u7528\u9019\u4e9b\u6578\u64da\u3002\u6578\u64da\u6301\u4e45\u5316\u7684\u5e38\u898b\u65b9\u5f0f\u5305\u62ec\u4f7f\u7528\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff08\u5982 MySQL\u3001PostgreSQL\uff09\u548c\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff08\u5982 MongoDB\uff09\u3002<\/p>\n<h2 id=\"%e6%95%b8%e7%b5%84%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-pTaZSoGpXN\">\u6578\u7d44\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u6578\u7d44\u662f\u4e00\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u7528\u65bc\u5b58\u5132\u591a\u500b\u76f8\u540c\u985e\u578b\u7684\u6578\u64da\u3002\u5728\u7de8\u7a0b\u4e2d\uff0c\u6578\u7d44\u901a\u5e38\u7528\u65bc\u7ba1\u7406\u548c\u64cd\u4f5c\u4e00\u7d44\u76f8\u95dc\u7684\u6578\u64da\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u500b\u96fb\u5b50\u5546\u52d9\u61c9\u7528\u4e2d\uff0c\u53ef\u80fd\u6703\u6709\u4e00\u500b\u6578\u7d44\u5b58\u5132\u7528\u6236\u7684\u8cfc\u7269\u8eca\u9805\u76ee\u3002<\/p>\n<h2 id=\"%e5%b0%87%e6%95%b8%e7%b5%84%e5%80%bc%e5%82%b3%e5%85%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%ad%a5%e9%a9%9f-pTaZSoGpXN\">\u5c07\u6578\u7d44\u503c\u50b3\u5165\u6578\u64da\u5eab\u7684\u6b65\u9a5f<\/h2>\n<p>\u5c07\u6578\u7d44\u7684\u503c\u50b3\u5165\u6578\u64da\u5eab\u901a\u5e38\u6d89\u53ca\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5<\/li>\n<li>\u6e96\u5099 SQL \u8a9e\u53e5<\/li>\n<li>\u57f7\u884c SQL \u8a9e\u53e5<\/li>\n<li>\u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5<\/li>\n<\/ul>\n<h3 id=\"1-%e5%bb%ba%e7%ab%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-pTaZSoGpXN\">1. \u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5efa\u7acb\u8207\u6578\u64da\u5eab\u7684\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 PHP \u548c MySQLi \u64f4\u5c55\u5efa\u7acb\u9023\u63a5\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\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<\/code><\/pre>\n<h3 id=\"2-%e6%ba%96%e5%82%99-sql-%e8%aa%9e%e5%8f%a5-pTaZSoGpXN\">2. \u6e96\u5099 SQL \u8a9e\u53e5<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u6e96\u5099\u4e00\u500b SQL \u8a9e\u53e5\u4f86\u63d2\u5165\u6578\u7d44\u4e2d\u7684\u503c\u3002\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba `products` \u7684\u8868\uff0c\u4e26\u4e14\u6211\u5011\u8981\u63d2\u5165\u4e00\u7d44\u7522\u54c1\u540d\u7a31\uff1a<\/p>\n<pre><code>\n$products = array(\"\u7522\u54c1A\", \"\u7522\u54c1B\", \"\u7522\u54c1C\");\n$sql = \"INSERT INTO products (product_name) VALUES (?)\";\n$stmt = $conn-&gt;prepare($sql);\n<\/code><\/pre>\n<h3 id=\"3-%e5%9f%b7%e8%a1%8c-sql-%e8%aa%9e%e5%8f%a5-pTaZSoGpXN\">3. \u57f7\u884c SQL \u8a9e\u53e5<\/h3>\n<p>\u7136\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u5faa\u74b0\u4f86\u904d\u6b77\u6578\u7d44\uff0c\u4e26\u5c07\u6bcf\u500b\u503c\u63d2\u5165\u5230\u6578\u64da\u5eab\u4e2d\uff1a<\/p>\n<pre><code>\nforeach ($products as $product) {\n    $stmt-&gt;bind_param(\"s\", $product);\n    $stmt-&gt;execute();\n}\n<\/code><\/pre>\n<h3 id=\"4-%e9%97%9c%e9%96%89%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-pTaZSoGpXN\">4. \u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5<\/h3>\n<p>\u6700\u5f8c\uff0c\u57f7\u884c\u5b8c\u6240\u6709\u64cd\u4f5c\u5f8c\uff0c\u8a18\u5f97\u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5\uff1a<\/p>\n<pre><code>\n$stmt-&gt;close();\n$conn-&gt;close();\n<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-pTaZSoGpXN\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u5c07\u6578\u7d44\u503c\u50b3\u5165\u6578\u64da\u5eab\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8003\u616e\uff1a<\/p>\n<ul>\n<li>\u78ba\u4fdd\u6578\u64da\u7684\u6709\u6548\u6027\u548c\u5b8c\u6574\u6027\uff0c\u4ee5\u907f\u514d\u63d2\u5165\u932f\u8aa4\u7684\u6578\u64da\u3002<\/li>\n<li>\u4f7f\u7528\u9810\u8655\u7406\u8a9e\u53e5\u4f86\u9632\u6b62 SQL \u6ce8\u5165\u653b\u64ca\u3002<\/li>\n<li>\u8003\u616e\u4f7f\u7528\u4e8b\u52d9\u4f86\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\uff0c\u7279\u5225\u662f\u5728\u6279\u91cf\u63d2\u5165\u6642\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-pTaZSoGpXN\">\u7e3d\u7d50<\/h2>\n<p>\u5c07\u6578\u7d44\u7684\u503c\u50b3\u5165\u6578\u64da\u5eab\u662f\u4e00\u500b\u5e38\u898b\u7684\u9700\u6c42\uff0c\u901a\u904e\u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5\u3001\u6e96\u5099 SQL \u8a9e\u53e5\u3001\u57f7\u884c\u8a9e\u53e5\u4ee5\u53ca\u95dc\u9589\u9023\u63a5\uff0c\u6211\u5011\u53ef\u4ee5\u6709\u6548\u5730\u5be6\u73fe\u6578\u64da\u6301\u4e45\u5316\u3002\u9019\u4e00\u904e\u7a0b\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u7684\u5b89\u5168\u6027\uff0c\u9084\u80fd\u78ba\u4fdd\u61c9\u7528\u7a0b\u5e8f\u7684\u7a69\u5b9a\u6027\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u7ba1\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\uff0c\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5c07\u6578\u7d44\u7684\u503c\u6709\u6548\u5730\u50b3\u5165\u6578\u64da\u5eab\uff0c\u5be6\u73fe\u6578\u64da\u6301\u4e45\u5316\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\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-183362","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183362","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=183362"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183362\/revisions"}],"predecessor-version":[{"id":183363,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183362\/revisions\/183363"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=183362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=183362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=183362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}