{"id":157422,"date":"2024-11-02T22:57:20","date_gmt":"2024-11-02T14:57:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/157422\/"},"modified":"2024-11-02T22:57:21","modified_gmt":"2024-11-02T14:57:21","slug":"%e6%84%9f%e6%81%a9%e5%b0%88%e6%a5%ad%e7%9a%84-php-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%ef%bc%88thank-php-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/157422\/","title":{"rendered":"\u611f\u6069\u5c08\u696d\u7684 PHP \u6578\u64da\u5eab\u64cd\u4f5c\uff08thank PHP \u6578\u64da\u5eab\u64cd\u4f5c\uff09"},"content":{"rendered":"<h1 id=\"%e6%84%9f%e6%81%a9%e5%b0%88%e6%a5%ad%e7%9a%84-php-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c-dpMRWglkck\">\u611f\u6069\u5c08\u696d\u7684 PHP \u6578\u64da\u5eab\u64cd\u4f5c<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u6578\u64da\u5eab\u64cd\u4f5c\u662f\u6bcf\u500b\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u7684\u6838\u5fc3\u3002PHP \u4f5c\u70ba\u4e00\u7a2e\u6d41\u884c\u7684\u4f3a\u670d\u5668\u7aef\u8173\u672c\u8a9e\u8a00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u7279\u5225\u662f\u8207 MySQL \u6578\u64da\u5eab\u7684\u4ea4\u4e92\u3002\u672c\u6587\u5c07\u63a2\u8a0e PHP \u6578\u64da\u5eab\u64cd\u4f5c\u7684\u91cd\u8981\u6027\u3001\u57fa\u672c\u64cd\u4f5c\u4ee5\u53ca\u6700\u4f73\u5be6\u8e10\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<h2 id=\"php-%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e9%97%9c%e4%bf%82-dpMRWglkck\">PHP \u8207\u6578\u64da\u5eab\u7684\u95dc\u4fc2<\/h2>\n<p>PHP \u7684\u5f37\u5927\u4e4b\u8655\u5728\u65bc\u5176\u8207\u6578\u64da\u5eab\u7684\u7121\u7e2b\u96c6\u6210\u3002\u901a\u904e PHP\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u9023\u63a5\u5230\u6578\u64da\u5eab\uff0c\u57f7\u884c\u67e5\u8a62\uff0c\u4e26\u8655\u7406\u8fd4\u56de\u7684\u6578\u64da\u3002\u9019\u4f7f\u5f97 PHP \u6210\u70ba\u958b\u767c\u52d5\u614b\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u7684\u7406\u60f3\u9078\u64c7\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c-dpMRWglkck\">\u57fa\u672c\u7684\u6578\u64da\u5eab\u64cd\u4f5c<\/h2>\n<p>\u5728 PHP \u4e2d\uff0c\u8207\u6578\u64da\u5eab\u7684\u4ea4\u4e92\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u57fa\u672c\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li><strong>\u9023\u63a5\u6578\u64da\u5eab\uff1a<\/strong>\u4f7f\u7528 mysqli \u6216 PDO \u64f4\u5c55\u4f86\u9023\u63a5\u6578\u64da\u5eab\u3002<\/li>\n<li><strong>\u57f7\u884c\u67e5\u8a62\uff1a<\/strong>\u4f7f\u7528 SQL \u8a9e\u53e5\u4f86\u67e5\u8a62\u6216\u4fee\u6539\u6578\u64da\u3002<\/li>\n<li><strong>\u8655\u7406\u7d50\u679c\uff1a<\/strong>\u5f9e\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u7d50\u679c\u4e26\u9032\u884c\u8655\u7406\u3002<\/li>\n<li><strong>\u95dc\u9589\u9023\u63a5\uff1a<\/strong>\u5728\u64cd\u4f5c\u5b8c\u6210\u5f8c\u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5\u3002<\/li>\n<\/ul>\n<h3 id=\"%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab-dpMRWglkck\">\u9023\u63a5\u6578\u64da\u5eab<\/h3>\n<pre><code>\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"database\";\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=\"%e5%9f%b7%e8%a1%8c%e6%9f%a5%e8%a9%a2-dpMRWglkck\">\u57f7\u884c\u67e5\u8a62<\/h3>\n<p>\u4e00\u65e6\u6210\u529f\u9023\u63a5\u5230\u6578\u64da\u5eab\uff0c\u5c31\u53ef\u4ee5\u57f7\u884c SQL \u67e5\u8a62\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u78bc\u5c55\u793a\u4e86\u5982\u4f55\u5f9e\u6578\u64da\u5eab\u4e2d\u9078\u64c7\u6578\u64da\uff1a<\/p>\n<pre><code>\n$sql = \"SELECT id, name FROM users\";\n$result = $conn-&gt;query($sql);\n\nif ($result-&gt;num_rows &gt; 0) {\n    \/\/ \u8f38\u51fa\u6bcf\u884c\u6578\u64da\n    while($row = $result-&gt;fetch_assoc()) {\n        echo \"id: \" . $row[\"id\"]. \" - Name: \" . $row[\"name\"]. \"<br>\";\n    }\n} else {\n    echo \"0 \u7d50\u679c\";\n}\n<\/code><\/pre>\n<h3 id=\"%e8%99%95%e7%90%86%e7%b5%90%e6%9e%9c-dpMRWglkck\">\u8655\u7406\u7d50\u679c<\/h3>\n<p>\u5728\u57f7\u884c\u67e5\u8a62\u5f8c\uff0c\u958b\u767c\u8005\u9700\u8981\u8655\u7406\u8fd4\u56de\u7684\u7d50\u679c\u3002\u53ef\u4ee5\u4f7f\u7528\u5faa\u74b0\u4f86\u904d\u6b77\u7d50\u679c\u96c6\uff0c\u4e26\u6839\u64da\u9700\u8981\u986f\u793a\u6216\u8655\u7406\u6578\u64da\u3002<\/p>\n<h3 id=\"%e9%97%9c%e9%96%89%e9%80%a3%e6%8e%a5-dpMRWglkck\">\u95dc\u9589\u9023\u63a5<\/h3>\n<pre><code>\n$conn-&gt;close();\n<\/code><\/pre>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-dpMRWglkck\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u9032\u884c PHP \u6578\u64da\u5eab\u64cd\u4f5c\u6642\uff0c\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u662f\u975e\u5e38\u91cd\u8981\u7684\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u9810\u8655\u7406\u8a9e\u53e5\uff1a<\/strong>\u9019\u53ef\u4ee5\u9632\u6b62 SQL \u6ce8\u5165\u653b\u64ca\uff0c\u589e\u5f37\u61c9\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u932f\u8aa4\u8655\u7406\uff1a<\/strong>\u78ba\u4fdd\u5728\u6578\u64da\u5eab\u64cd\u4f5c\u4e2d\u5be6\u65bd\u9069\u7576\u7684\u932f\u8aa4\u8655\u7406\uff0c\u4ee5\u4fbf\u80fd\u5920\u5feb\u901f\u8b58\u5225\u548c\u89e3\u6c7a\u554f\u984c\u3002<\/li>\n<li><strong>\u6578\u64da\u9a57\u8b49\uff1a<\/strong>\u5728\u5c07\u6578\u64da\u63d2\u5165\u6578\u64da\u5eab\u4e4b\u524d\uff0c\u9032\u884c\u5fc5\u8981\u7684\u9a57\u8b49\uff0c\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6e96\u78ba\u6027\u3002<\/li>\n<li><strong>\u5b9a\u671f\u5099\u4efd\uff1a<\/strong>\u5b9a\u671f\u5099\u4efd\u6578\u64da\u5eab\uff0c\u4ee5\u9632\u6b62\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-dpMRWglkck\">\u7d50\u8ad6<\/h2>\n<p>PHP \u6578\u64da\u5eab\u64cd\u4f5c\u662f\u73fe\u4ee3\u7db2\u7d61\u61c9\u7528\u7a0b\u5e8f\u7684\u57fa\u77f3\u3002\u901a\u904e\u638c\u63e1\u57fa\u672c\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5275\u5efa\u5b89\u5168\u3001\u9ad8\u6548\u7684\u61c9\u7528\u7a0b\u5e8f\u3002\u96a8\u8457\u6280\u8853\u7684\u767c\u5c55\uff0c\u6301\u7e8c\u5b78\u7fd2\u548c\u9069\u61c9\u65b0\u7684\u5de5\u5177\u548c\u6280\u8853\u5c07\u662f\u6bcf\u4f4d\u958b\u767c\u8005\u7684\u5fc5\u4fee\u8ab2\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684 PHP \u61c9\u7528\u7a0b\u5e8f\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u9805\u76ee\u9084\u662f\u5927\u578b\u4f01\u696d\u61c9\u7528\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u611f\u6069\u5c08\u696d\u7684 PHP \u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u63d0\u5347\u60a8\u7684\u7db2\u7ad9\u6027\u80fd\u8207\u6578\u64da\u7ba1\u7406\u6548\u7387\uff0c\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u8655\u7406\u89e3\u6c7a\u65b9\u6848\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-157422","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/157422","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=157422"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/157422\/revisions"}],"predecessor-version":[{"id":157423,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/157422\/revisions\/157423"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=157422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=157422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=157422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}