{"id":96428,"date":"2024-10-20T09:20:19","date_gmt":"2024-10-20T01:20:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/96428\/"},"modified":"2024-10-20T09:20:19","modified_gmt":"2024-10-20T01:20:19","slug":"phpmysql%e7%b6%b2%e7%ab%99%e6%9e%b6%e6%a7%8b%e6%96%b9%e9%9d%a2%e7%9a%84%e4%b8%80%e4%ba%9b%e8%aa%8d%e8%ad%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/96428\/","title":{"rendered":"PHP+MySQL\u7db2\u7ad9\u67b6\u69cb\u65b9\u9762\u7684\u4e00\u4e9b\u8a8d\u8b58"},"content":{"rendered":"<h1 id=\"phpmysql%e7%b6%b2%e7%ab%99%e6%9e%b6%e6%a7%8b%e6%96%b9%e9%9d%a2%e7%9a%84%e4%b8%80%e4%ba%9b%e8%aa%8d%e8%ad%98-gOPTbuPfnS\">PHP+MySQL\u7db2\u7ad9\u67b6\u69cb\u65b9\u9762\u7684\u4e00\u4e9b\u8a8d\u8b58<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cPHP\u548cMySQL\u5df2\u6210\u70ba\u6700\u53d7\u6b61\u8fce\u7684\u7db2\u7ad9\u958b\u767c\u6280\u8853\u4e4b\u4e00\u3002\u9019\u5169\u8005\u7684\u7d50\u5408\u4e0d\u50c5\u80fd\u5920\u63d0\u4f9b\u5f37\u5927\u7684\u529f\u80fd\uff0c\u9084\u80fd\u5920\u7c21\u5316\u958b\u767c\u904e\u7a0b\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u5feb\u901f\u69cb\u5efa\u52d5\u614b\u7db2\u7ad9\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0ePHP\u548cMySQL\u7684\u57fa\u672c\u6982\u5ff5\u3001\u67b6\u69cb\u53ca\u5176\u5728\u7db2\u7ad9\u958b\u767c\u4e2d\u7684\u61c9\u7528\u3002<\/p>\n<h2 id=\"php%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-gOPTbuPfnS\">PHP\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>PHP\uff08Hypertext Preprocessor\uff09\u662f\u4e00\u7a2e\u958b\u6e90\u7684\u4f3a\u670d\u5668\u7aef\u8173\u672c\u8a9e\u8a00\uff0c\u5c08\u9580\u7528\u65bc\u7db2\u9801\u958b\u767c\u3002\u5b83\u7684\u8a9e\u6cd5\u7c21\u55ae\u6613\u5b78\uff0c\u4e26\u4e14\u80fd\u5920\u8207HTML\u7121\u7e2b\u96c6\u6210\u3002PHP\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u8de8\u5e73\u53f0\u6027\uff1a<\/strong>PHP\u53ef\u4ee5\u5728\u591a\u7a2e\u64cd\u4f5c\u7cfb\u7d71\u4e0a\u904b\u884c\uff0c\u5305\u62ecWindows\u3001Linux\u548cmacOS\u3002<\/li>\n<li><strong>\u958b\u6e90\u6027\uff1a<\/strong>\u4f5c\u70ba\u4e00\u7a2e\u958b\u6e90\u8a9e\u8a00\uff0cPHP\u64c1\u6709\u9f90\u5927\u7684\u793e\u5340\u652f\u6301\u548c\u8c50\u5bcc\u7684\u8cc7\u6e90\u3002<\/li>\n<li><strong>\u5f37\u5927\u7684\u6578\u64da\u5eab\u652f\u6301\uff1a<\/strong>PHP\u80fd\u5920\u8207\u591a\u7a2e\u6578\u64da\u5eab\u7cfb\u7d71\u9032\u884c\u4ea4\u4e92\uff0c\u5176\u4e2dMySQL\u662f\u6700\u5e38\u7528\u7684\u9078\u64c7\u4e4b\u4e00\u3002<\/li>\n<\/ul>\n<h2 id=\"mysql%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-gOPTbuPfnS\">MySQL\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>MySQL\u662f\u4e00\u7a2e\u958b\u6e90\u7684\u95dc\u806f\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u5b83\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u9ad8\u6548\u80fd\uff1a<\/strong>MySQL\u80fd\u5920\u8655\u7406\u5927\u91cf\u6578\u64da\u4e26\u63d0\u4f9b\u5feb\u901f\u7684\u67e5\u8a62\u97ff\u61c9\u3002<\/li>\n<li><strong>\u53ef\u9760\u6027\uff1a<\/strong>MySQL\u63d0\u4f9b\u4e86\u6578\u64da\u5b8c\u6574\u6027\u548c\u5b89\u5168\u6027\uff0c\u78ba\u4fdd\u6578\u64da\u4e0d\u6703\u4e1f\u5931\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\uff1a<\/strong>MySQL\u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\u548c\u67e5\u8a62\u8a9e\u8a00\uff0c\u65b9\u4fbf\u958b\u767c\u8005\u6839\u64da\u9700\u6c42\u9032\u884c\u8a2d\u8a08\u3002<\/li>\n<\/ul>\n<h2 id=\"php%e8%88%87mysql%e7%9a%84%e6%9e%b6%e6%a7%8b-gOPTbuPfnS\">PHP\u8207MySQL\u7684\u67b6\u69cb<\/h2>\n<p>PHP\u548cMySQL\u7684\u7d50\u5408\u901a\u5e38\u9075\u5faa\u4ee5\u4e0b\u67b6\u69cb\uff1a<\/p>\n<pre>\n1. \u7528\u6236\u901a\u904e\u700f\u89bd\u5668\u767c\u9001\u8acb\u6c42\u5230\u4f3a\u670d\u5668\u3002\n2. \u4f3a\u670d\u5668\u63a5\u6536\u5230\u8acb\u6c42\u5f8c\uff0cPHP\u89e3\u91cb\u5668\u958b\u59cb\u57f7\u884c\u76f8\u61c9\u7684PHP\u4ee3\u78bc\u3002\n3. PHP\u4ee3\u78bc\u4e2d\u53ef\u80fd\u5305\u542b\u5c0dMySQL\u6578\u64da\u5eab\u7684\u67e5\u8a62\u3002\n4. MySQL\u6839\u64da\u8acb\u6c42\u8fd4\u56de\u6578\u64da\u7d66PHP\u3002\n5. PHP\u5c07\u6578\u64da\u8655\u7406\u5f8c\u751f\u6210HTML\u9801\u9762\uff0c\u4e26\u5c07\u5176\u8fd4\u56de\u7d66\u7528\u6236\u7684\u700f\u89bd\u5668\u3002\n<\/pre>\n<h3 id=\"%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a2%bc-gOPTbuPfnS\">\u793a\u4f8b\u4ee3\u78bc<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684PHP\u8207MySQL\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5f9e\u6578\u64da\u5eab\u4e2d\u6aa2\u7d22\u6578\u64da\uff1a<\/p>\n<pre><code>&lt;?php\n\/\/ \u9023\u63a5\u5230MySQL\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\/\/ \u67e5\u8a62\u6578\u64da\n$sql = \"SELECT id, name FROM users\";\n$result = $conn-&gt;query($sql);\n\n\/\/ \u8f38\u51fa\u6578\u64da\nif ($result-&gt;num_rows &gt; 0) {\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=\"phpmysql%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-gOPTbuPfnS\">PHP+MySQL\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>PHP\u548cMySQL\u7684\u7d44\u5408\u9069\u7528\u65bc\u591a\u7a2e\u61c9\u7528\u5834\u666f\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u5167\u5bb9\u7ba1\u7406\u7cfb\u7d71\uff08CMS\uff09\uff1a<\/strong>\u8a31\u591a\u6d41\u884c\u7684CMS\u5982WordPress\u548cDrupal\u90fd\u662f\u57fa\u65bcPHP\u548cMySQL\u69cb\u5efa\u7684\u3002<\/li>\n<li><strong>\u96fb\u5b50\u5546\u52d9\u7db2\u7ad9\uff1a<\/strong>\u8a31\u591a\u96fb\u5b50\u5546\u52d9\u5e73\u53f0\u4f7f\u7528PHP\u548cMySQL\u4f86\u8655\u7406\u7528\u6236\u6578\u64da\u548c\u4ea4\u6613\u3002<\/li>\n<li><strong>\u793e\u4ea4\u5a92\u9ad4\u5e73\u53f0\uff1a<\/strong>\u793e\u4ea4\u5a92\u9ad4\u7db2\u7ad9\u901a\u5e38\u9700\u8981\u5feb\u901f\u8655\u7406\u5927\u91cf\u7528\u6236\u6578\u64da\uff0cPHP\u548cMySQL\u80fd\u5920\u6eff\u8db3\u9019\u4e00\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-gOPTbuPfnS\">\u7e3d\u7d50<\/h2>\n<p>PHP\u548cMySQL\u7684\u7d50\u5408\u70ba\u7db2\u7ad9\u958b\u767c\u63d0\u4f9b\u4e86\u4e00\u500b\u5f37\u5927\u800c\u9748\u6d3b\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u7db2\u7ad9\u9084\u662f\u5927\u578b\u61c9\u7528\uff0c\u9019\u7a2e\u67b6\u69cb\u90fd\u80fd\u5920\u6709\u6548\u5730\u652f\u6301\u5404\u7a2e\u9700\u6c42\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u904b\u884c\u60a8\u7684PHP\u548cMySQL\u61c9\u7528\uff0cServer.HK\u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u642d\u5efa\u548c\u7ba1\u7406\u60a8\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3PHP+MySQL\u7db2\u7ad9\u67b6\u69cb\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u638c\u63e1\u6578\u64da\u5eab\u7ba1\u7406\u3001\u52d5\u614b\u5167\u5bb9\u751f\u6210\u53ca\u7db2\u7ad9\u6027\u80fd\u512a\u5316\u6280\u5de7\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-96428","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96428","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=96428"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96428\/revisions"}],"predecessor-version":[{"id":96429,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96428\/revisions\/96429"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=96428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=96428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=96428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}