{"id":187750,"date":"2024-11-11T16:52:20","date_gmt":"2024-11-11T08:52:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/187750\/"},"modified":"2024-11-11T16:52:21","modified_gmt":"2024-11-11T08:52:21","slug":"%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e5%85%a7%e5%ae%b9%e8%83%bd%e5%90%a6%e7%9b%b4%e6%8e%a5%e9%a1%af%e7%a4%ba%e5%9c%a8%e9%8f%88%e6%8e%a5%e4%b8%ad%ef%bc%9f-%e9%8f%88%e6%8e%a5%e9%a1%af%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/187750\/","title":{"rendered":"\u6578\u64da\u5eab\u4e2d\u7684\u5167\u5bb9\u80fd\u5426\u76f4\u63a5\u986f\u793a\u5728\u93c8\u63a5\u4e2d\uff1f (\u93c8\u63a5\u986f\u793a\u6578\u64da\u5eab\u88e1\u7684\u5167\u5bb9\u55ce)"},"content":{"rendered":"<h1 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e5%85%a7%e5%ae%b9%e8%83%bd%e5%90%a6%e7%9b%b4%e6%8e%a5%e9%a1%af%e7%a4%ba%e5%9c%a8%e9%8f%88%e6%8e%a5%e4%b8%ad%ef%bc%9f-xkhMkkkLsu\">\u6578\u64da\u5eab\u4e2d\u7684\u5167\u5bb9\u80fd\u5426\u76f4\u63a5\u986f\u793a\u5728\u93c8\u63a5\u4e2d\uff1f<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u666e\u904d\u3002\u8a31\u591a\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u4f9d\u8cf4\u65bc\u6578\u64da\u5eab\u4f86\u5b58\u5132\u548c\u7ba1\u7406\u4fe1\u606f\u3002\u7576\u7528\u6236\u8a2a\u554f\u67d0\u500b\u93c8\u63a5\u6642\uff0c\u662f\u5426\u80fd\u76f4\u63a5\u986f\u793a\u6578\u64da\u5eab\u4e2d\u7684\u5167\u5bb9\uff0c\u9019\u662f\u4e00\u500b\u503c\u5f97\u63a2\u8a0e\u7684\u554f\u984c\u3002\u672c\u6587\u5c07\u6df1\u5165\u5206\u6790\u9019\u4e00\u4e3b\u984c\uff0c\u4e26\u63a2\u8a0e\u5176\u80cc\u5f8c\u7684\u6280\u8853\u539f\u7406\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%88%87%e9%8f%88%e6%8e%a5%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-xkhMkkkLsu\">\u6578\u64da\u5eab\u8207\u93c8\u63a5\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u6578\u64da\u5eab\u662f\u4e00\u7a2e\u7d50\u69cb\u5316\u7684\u6578\u64da\u5b58\u5132\u7cfb\u7d71\uff0c\u901a\u5e38\u7528\u65bc\u5b58\u5132\u5927\u91cf\u7684\u6578\u64da\u3002\u93c8\u63a5\u5247\u662f\u7528\u6236\u5728\u4e92\u806f\u7db2\u4e0a\u8a2a\u554f\u8cc7\u6e90\u7684\u65b9\u5f0f\u3002\u7576\u7528\u6236\u9ede\u64ca\u93c8\u63a5\u6642\uff0c\u901a\u5e38\u6703\u8acb\u6c42\u4e00\u500b\u7279\u5b9a\u7684\u7db2\u9801\u6216\u8cc7\u6e90\u3002\u9019\u500b\u904e\u7a0b\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u5167\u5bb9\u662f\u5426\u80fd\u76f4\u63a5\u986f\u793a\u5728\u93c8\u63a5\u4e2d\uff0c\u53d6\u6c7a\u65bc\u591a\u500b\u56e0\u7d20\uff0c\u5305\u62ec\u5f8c\u7aef\u6280\u8853\u3001\u6578\u64da\u5eab\u8a2d\u8a08\u548c\u7db2\u9801\u67b6\u69cb\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%b0%87%e6%95%b8%e6%93%9a%e5%ba%ab%e5%85%a7%e5%ae%b9%e9%a1%af%e7%a4%ba%e5%9c%a8%e9%8f%88%e6%8e%a5%e4%b8%ad-xkhMkkkLsu\">\u5982\u4f55\u5c07\u6578\u64da\u5eab\u5167\u5bb9\u986f\u793a\u5728\u93c8\u63a5\u4e2d<\/h2>\n<p>\u8981\u5c07\u6578\u64da\u5eab\u4e2d\u7684\u5167\u5bb9\u986f\u793a\u5728\u93c8\u63a5\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u901a\u904e\u5f8c\u7aef\u7a0b\u5f0f\u78bc\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u6280\u8853\u548c\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u52d5\u614b\u7db2\u9801\u751f\u6210\uff1a<\/strong>\u4f7f\u7528\u4f3a\u670d\u5668\u7aef\u8a9e\u8a00\uff08\u5982 PHP\u3001Python\u3001Ruby \u7b49\uff09\u4f86\u751f\u6210\u52d5\u614b\u7db2\u9801\u3002\u7576\u7528\u6236\u8a2a\u554f\u67d0\u500b\u93c8\u63a5\u6642\uff0c\u4f3a\u670d\u5668\u6703\u6839\u64da\u8acb\u6c42\u5f9e\u6578\u64da\u5eab\u4e2d\u63d0\u53d6\u76f8\u61c9\u7684\u6578\u64da\uff0c\u7136\u5f8c\u751f\u6210 HTML \u9801\u9762\u8fd4\u56de\u7d66\u7528\u6236\u3002<\/li>\n<li><strong>RESTful API\uff1a<\/strong>\u901a\u904e API \u5c07\u6578\u64da\u5eab\u5167\u5bb9\u4ee5 JSON \u683c\u5f0f\u63d0\u4f9b\u7d66\u524d\u7aef\u61c9\u7528\u3002\u524d\u7aef\u53ef\u4ee5\u6839\u64da\u7528\u6236\u7684\u64cd\u4f5c\u8acb\u6c42\u76f8\u61c9\u7684\u6578\u64da\uff0c\u4e26\u52d5\u614b\u66f4\u65b0\u9801\u9762\u5167\u5bb9\u3002<\/li>\n<li><strong>URL \u53c3\u6578\uff1a<\/strong>\u5728\u93c8\u63a5\u4e2d\u4f7f\u7528 URL \u53c3\u6578\u4f86\u50b3\u905e\u7279\u5b9a\u7684\u6578\u64da\u8b58\u5225\u7b26\uff08\u5982 ID\uff09\u3002\u4f3a\u670d\u5668\u53ef\u4ee5\u6839\u64da\u9019\u4e9b\u53c3\u6578\u67e5\u8a62\u6578\u64da\u5eab\uff0c\u4e26\u986f\u793a\u76f8\u61c9\u7684\u5167\u5bb9\u3002\u4f8b\u5982\uff0c\u93c8\u63a5 <code>https:\/\/example.com\/article?id=123<\/code> \u53ef\u4ee5\u7528\u4f86\u67e5\u8a62 ID \u70ba 123 \u7684\u6587\u7ae0\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a2%bc-xkhMkkkLsu\">\u793a\u4f8b\u4ee3\u78bc<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684 PHP \u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5f9e\u6578\u64da\u5eab\u4e2d\u63d0\u53d6\u5167\u5bb9\u4e26\u986f\u793a\u5728\u7db2\u9801\u4e0a\uff1a<\/p>\n<pre><code>&lt;?php\n\/\/ \u9023\u63a5\u5230\u6578\u64da\u5eab\n$conn = new mysqli(\"localhost\", \"username\", \"password\", \"database\");\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"\u9023\u63a5\u5931\u6557: \" . $conn-&gt;connect_error);\n}\n\n\/\/ \u7372\u53d6 URL \u53c3\u6578\n$id = $_GET['id'];\n\n\/\/ \u67e5\u8a62\u6578\u64da\u5eab\n$sql = \"SELECT title, content FROM articles WHERE id = $id\";\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 \"&lt;h1&gt;\" . $row[\"title\"] . \"&lt;\/h1&gt;\";\n        echo \"&lt;p&gt;\" . $row[\"content\"] . \"&lt;\/p&gt;\";\n    }\n} else {\n    echo \"\u6c92\u6709\u627e\u5230\u6587\u7ae0\";\n}\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-xkhMkkkLsu\">\u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u5728\u5c07\u6578\u64da\u5eab\u5167\u5bb9\u986f\u793a\u5728\u93c8\u63a5\u4e2d\u6642\uff0c\u5b89\u5168\u6027\u662f\u5fc5\u9808\u8003\u616e\u7684\u91cd\u8981\u56e0\u7d20\u3002\u4f7f\u7528 URL \u53c3\u6578\u6642\uff0c\u61c9\u8a72\u5c0d\u8f38\u5165\u9032\u884c\u9a57\u8b49\u548c\u904e\u6ffe\uff0c\u4ee5\u9632\u6b62 SQL \u6ce8\u5165\u653b\u64ca\u3002\u6b64\u5916\uff0c\u61c9\u8a72\u4f7f\u7528 HTTPS \u5354\u8b70\u4f86\u52a0\u5bc6\u6578\u64da\u50b3\u8f38\uff0c\u4fdd\u8b77\u7528\u6236\u7684\u96b1\u79c1\u548c\u6578\u64da\u5b89\u5168\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-xkhMkkkLsu\">\u7d50\u8ad6<\/h2>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0c\u6578\u64da\u5eab\u4e2d\u7684\u5167\u5bb9\u53ef\u4ee5\u901a\u904e\u9069\u7576\u7684\u6280\u8853\u624b\u6bb5\u76f4\u63a5\u986f\u793a\u5728\u93c8\u63a5\u4e2d\u3002\u9019\u9700\u8981\u5f8c\u7aef\u7a0b\u5f0f\u78bc\u7684\u652f\u6301\uff0c\u4ee5\u53ca\u5c0d\u6578\u64da\u7684\u5b89\u5168\u7ba1\u7406\u3002\u96a8\u8457\u6280\u8853\u7684\u767c\u5c55\uff0c\u8d8a\u4f86\u8d8a\u591a\u7684\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u9078\u64c7\u4f7f\u7528\u52d5\u614b\u751f\u6210\u7684\u5167\u5bb9\u4f86\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc\u5982\u4f55\u5728\u60a8\u7684\u7db2\u7ad9\u4e0a\u5be6\u73fe\u9019\u4e9b\u6280\u8853\u6709\u8208\u8da3\uff0c\u6216\u8005\u60f3\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u7684\u8cc7\u8a0a\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u8cc7\u6e90\u548c\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u8a0e\u6578\u64da\u5eab\u5167\u5bb9\u662f\u5426\u80fd\u76f4\u63a5\u986f\u793a\u5728\u93c8\u63a5\u4e2d\uff0c\u4ee5\u53ca\u93c8\u63a5\u5982\u4f55\u5448\u73fe\u6578\u64da\u5eab\u5167\u7684\u8cc7\u8a0a\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-187750","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187750","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=187750"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187750\/revisions"}],"predecessor-version":[{"id":187751,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187750\/revisions\/187751"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=187750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=187750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=187750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}