{"id":171281,"date":"2024-11-07T01:26:23","date_gmt":"2024-11-06T17:26:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/171281\/"},"modified":"2024-11-07T01:26:24","modified_gmt":"2024-11-06T17:26:24","slug":"%e5%89%8d%e7%ab%af%e5%a6%82%e4%bd%95%e8%88%87%e6%9c%8d%e5%8b%99%e5%99%a8%e5%92%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bb%ba%e7%ab%8b%e9%97%9c%e4%bf%82%ef%bc%9f-%e5%89%8d%e7%ab%af-%e6%9c%8d%e5%8b%99","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/171281\/","title":{"rendered":"\u524d\u7aef\u5982\u4f55\u8207\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u5efa\u7acb\u95dc\u4fc2\uff1f (\u524d\u7aef \u670d\u52d9\u5668 \u6578\u64da\u5eab\u95dc\u4fc2)"},"content":{"rendered":"<h1 id=\"%e5%89%8d%e7%ab%af%e5%a6%82%e4%bd%95%e8%88%87%e6%9c%8d%e5%8b%99%e5%99%a8%e5%92%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bb%ba%e7%ab%8b%e9%97%9c%e4%bf%82%ef%bc%9f-QztOhPzQKq\">\u524d\u7aef\u5982\u4f55\u8207\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u5efa\u7acb\u95dc\u4fc2\uff1f<\/h1>\n<p>\u5728\u73fe\u4ee3\u7db2\u9801\u958b\u767c\u4e2d\uff0c\u524d\u7aef\u3001\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u4e4b\u9593\u7684\u95dc\u4fc2\u81f3\u95dc\u91cd\u8981\u3002\u9019\u4e09\u8005\u7684\u5354\u4f5c\u80fd\u5920\u5be6\u73fe\u52d5\u614b\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u7684\u529f\u80fd\uff0c\u4e26\u63d0\u4f9b\u7528\u6236\u6240\u9700\u7684\u6578\u64da\u548c\u670d\u52d9\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u524d\u7aef\u5982\u4f55\u8207\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u5efa\u7acb\u95dc\u4fc2\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e5%89%8d%e7%ab%af%e7%9a%84%e8%a7%92%e8%89%b2-QztOhPzQKq\">\u524d\u7aef\u7684\u89d2\u8272<\/h2>\n<p>\u524d\u7aef\u662f\u7528\u6236\u8207\u7db2\u7ad9\u6216\u61c9\u7528\u7a0b\u5e8f\u4e92\u52d5\u7684\u90e8\u5206\uff0c\u901a\u5e38\u7531 HTML\u3001CSS \u548c JavaScript \u7d44\u6210\u3002\u524d\u7aef\u7684\u4e3b\u8981\u4efb\u52d9\u662f\u63d0\u4f9b\u7528\u6236\u754c\u9762\uff0c\u4e26\u901a\u904e\u8207\u670d\u52d9\u5668\u7684\u901a\u4fe1\u4f86\u7372\u53d6\u6216\u63d0\u4ea4\u6578\u64da\u3002\u9019\u7a2e\u901a\u4fe1\u901a\u5e38\u662f\u901a\u904e HTTP \u8acb\u6c42\u4f86\u5be6\u73fe\u7684\u3002<\/p>\n<h2 id=\"%e6%9c%8d%e5%8b%99%e5%99%a8%e7%9a%84%e8%a7%92%e8%89%b2-QztOhPzQKq\">\u670d\u52d9\u5668\u7684\u89d2\u8272<\/h2>\n<p>\u670d\u52d9\u5668\u662f\u8655\u7406\u8acb\u6c42\u4e26\u63d0\u4f9b\u6578\u64da\u7684\u4e2d\u4ecb\u3002\u7576\u524d\u7aef\u767c\u9001\u8acb\u6c42\u6642\uff0c\u670d\u52d9\u5668\u6703\u6839\u64da\u8acb\u6c42\u7684\u5167\u5bb9\u9032\u884c\u76f8\u61c9\u7684\u8655\u7406\uff0c\u4e26\u5c07\u7d50\u679c\u8fd4\u56de\u7d66\u524d\u7aef\u3002\u670d\u52d9\u5668\u53ef\u4ee5\u4f7f\u7528\u591a\u7a2e\u6280\u8853\u4f86\u5be6\u73fe\uff0c\u4f8b\u5982 Node.js\u3001PHP\u3001Python \u7b49\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e8%a7%92%e8%89%b2-QztOhPzQKq\">\u6578\u64da\u5eab\u7684\u89d2\u8272<\/h2>\n<p>\u6578\u64da\u5eab\u662f\u7528\u4f86\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\u7684\u7cfb\u7d71\u3002\u7576\u670d\u52d9\u5668\u9700\u8981\u8a2a\u554f\u6216\u4fee\u6539\u6578\u64da\u6642\uff0c\u5b83\u6703\u8207\u6578\u64da\u5eab\u9032\u884c\u4ea4\u4e92\u3002\u5e38\u898b\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u5305\u62ec MySQL\u3001PostgreSQL \u548c MongoDB \u7b49\u3002\u6578\u64da\u5eab\u7684\u8a2d\u8a08\u548c\u7d50\u69cb\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e5%89%8d%e7%ab%af%e8%88%87%e6%9c%8d%e5%8b%99%e5%99%a8%e7%9a%84%e9%80%9a%e4%bf%a1-QztOhPzQKq\">\u524d\u7aef\u8207\u670d\u52d9\u5668\u7684\u901a\u4fe1<\/h2>\n<p>\u524d\u7aef\u8207\u670d\u52d9\u5668\u4e4b\u9593\u7684\u901a\u4fe1\u901a\u5e38\u4f7f\u7528 AJAX\uff08Asynchronous JavaScript and XML\uff09\u6216 Fetch API\u3002\u9019\u4e9b\u6280\u8853\u5141\u8a31\u524d\u7aef\u5728\u4e0d\u91cd\u65b0\u52a0\u8f09\u9801\u9762\u7684\u60c5\u6cc1\u4e0b\u5411\u670d\u52d9\u5668\u767c\u9001\u8acb\u6c42\u4e26\u63a5\u6536\u97ff\u61c9\u3002<\/p>\n<pre><code>\n\/\/ \u4f7f\u7528 Fetch API \u5411\u670d\u52d9\u5668\u767c\u9001 GET \u8acb\u6c42\nfetch('https:\/\/api.example.com\/data')\n  .then(response =&gt; response.json())\n  .then(data =&gt; {\n    console.log(data);\n  })\n  .catch(error =&gt; {\n    console.error('Error:', error);\n  });\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u524d\u7aef\u4f7f\u7528 Fetch API \u5411\u670d\u52d9\u5668\u767c\u9001\u8acb\u6c42\uff0c\u4e26\u5728\u7372\u53d6\u5230\u6578\u64da\u5f8c\u9032\u884c\u8655\u7406\u3002<\/p>\n<h2 id=\"%e6%9c%8d%e5%8b%99%e5%99%a8%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e4%ba%a4%e4%ba%92-QztOhPzQKq\">\u670d\u52d9\u5668\u8207\u6578\u64da\u5eab\u7684\u4ea4\u4e92<\/h2>\n<p>\u7576\u670d\u52d9\u5668\u63a5\u6536\u5230\u4f86\u81ea\u524d\u7aef\u7684\u8acb\u6c42\u6642\uff0c\u5b83\u53ef\u80fd\u9700\u8981\u5f9e\u6578\u64da\u5eab\u4e2d\u6aa2\u7d22\u6578\u64da\u6216\u5c07\u6578\u64da\u5beb\u5165\u6578\u64da\u5eab\u3002\u9019\u901a\u5e38\u6d89\u53ca\u5230 SQL \u67e5\u8a62\u6216\u4f7f\u7528 ORM\uff08Object-Relational Mapping\uff09\u5de5\u5177\u3002<\/p>\n<pre><code>\n\/\/ \u4f7f\u7528 Node.js \u548c MySQL \u9032\u884c\u6578\u64da\u5eab\u67e5\u8a62\nconst mysql = require('mysql');\nconst connection = mysql.createConnection({\n  host: 'localhost',\n  user: 'user',\n  password: 'password',\n  database: 'database'\n});\n\nconnection.connect();\n\nconnection.query('SELECT * FROM users', (error, results) =&gt; {\n  if (error) throw error;\n  console.log(results);\n});\n\nconnection.end();\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0cNode.js \u670d\u52d9\u5668\u4f7f\u7528 MySQL \u9023\u63a5\u4f86\u67e5\u8a62\u6578\u64da\u5eab\u4e2d\u7684\u7528\u6236\u4fe1\u606f\uff0c\u4e26\u5c07\u7d50\u679c\u8fd4\u56de\u7d66\u524d\u7aef\u3002<\/p>\n<h2 id=\"%e5%89%8d%e7%ab%af%e3%80%81%e6%9c%8d%e5%8b%99%e5%99%a8%e5%92%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%95%b4%e5%90%88-QztOhPzQKq\">\u524d\u7aef\u3001\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u7684\u6574\u5408<\/h2>\n<p>\u524d\u7aef\u3001\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u7684\u6574\u5408\u662f\u73fe\u4ee3\u61c9\u7528\u7a0b\u5e8f\u958b\u767c\u7684\u6838\u5fc3\u3002\u524d\u7aef\u901a\u904e API \u8207\u670d\u52d9\u5668\u9032\u884c\u901a\u4fe1\uff0c\u670d\u52d9\u5668\u5247\u8ca0\u8cac\u8655\u7406\u8acb\u6c42\u4e26\u8207\u6578\u64da\u5eab\u4ea4\u4e92\u3002\u9019\u7a2e\u67b6\u69cb\u4f7f\u5f97\u61c9\u7528\u7a0b\u5e8f\u80fd\u5920\u9748\u6d3b\u5730\u64f4\u5c55\u548c\u7dad\u8b77\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-QztOhPzQKq\">\u7e3d\u7d50<\/h2>\n<p>\u524d\u7aef\u3001\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u4e4b\u9593\u7684\u95dc\u4fc2\u662f\u73fe\u4ee3\u7db2\u9801\u958b\u767c\u7684\u57fa\u77f3\u3002\u901a\u904e\u6709\u6548\u7684\u901a\u4fe1\u548c\u6578\u64da\u7ba1\u7406\uff0c\u958b\u767c\u8005\u80fd\u5920\u5275\u5efa\u51fa\u529f\u80fd\u5f37\u5927\u4e14\u7528\u6236\u53cb\u597d\u7684\u61c9\u7528\u7a0b\u5e8f\u3002\u4e86\u89e3\u9019\u4e09\u8005\u4e4b\u9593\u7684\u4e92\u52d5\u65b9\u5f0f\uff0c\u5c0d\u65bc\u4efb\u4f55\u5e0c\u671b\u9032\u5165\u7db2\u9801\u958b\u767c\u9818\u57df\u7684\u4eba\u4f86\u8aaa\u90fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u548c\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u524d\u7aef\u5982\u4f55\u901a\u904eAPI\u8207\u670d\u52d9\u5668\u548c\u6578\u64da\u5eab\u5efa\u7acb\u95dc\u4fc2\uff0c\u5be6\u73fe\u6578\u64da\u4ea4\u4e92\u548c\u52d5\u614b\u5167\u5bb9\u5448\u73fe\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-171281","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171281","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=171281"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171281\/revisions"}],"predecessor-version":[{"id":171282,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171281\/revisions\/171282"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=171281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=171281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=171281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}