{"id":75680,"date":"2024-10-16T00:19:28","date_gmt":"2024-10-15T16:19:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/75680\/"},"modified":"2024-10-16T00:19:28","modified_gmt":"2024-10-15T16:19:28","slug":"mysql_fetch_row-%e5%92%8c-mysql_fetch_array-%e7%9a%84%e5%b7%ae%e7%95%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/75680\/","title":{"rendered":"MySQL_FETCH_ROW() \u548c MySQL_FETCH_ARRAY() \u7684\u5dee\u7570"},"content":{"rendered":"<h1 id=\"mysql_fetch_row-%e5%92%8c-mysql_fetch_array-%e7%9a%84%e5%b7%ae%e7%95%b0-osdRGQllyC\">MySQL_FETCH_ROW() \u548c MySQL_FETCH_ARRAY() \u7684\u5dee\u7570<\/h1>\n<p>\u5728\u4f7f\u7528 PHP \u8207 MySQL \u9032\u884c\u8cc7\u6599\u5eab\u64cd\u4f5c\u6642\uff0c\u958b\u767c\u8005\u7d93\u5e38\u9700\u8981\u5f9e\u67e5\u8a62\u7d50\u679c\u4e2d\u63d0\u53d6\u8cc7\u6599\u3002MySQL \u63d0\u4f9b\u4e86\u591a\u7a2e\u51fd\u6578\u4f86\u9054\u6210\u9019\u4e00\u76ee\u7684\uff0c\u5176\u4e2d <code>mysql_fetch_row()<\/code> \u548c <code>mysql_fetch_array()<\/code> \u662f\u6700\u5e38\u7528\u7684\u5169\u500b\u51fd\u6578\u3002\u96d6\u7136\u5b83\u5011\u7684\u529f\u80fd\u76f8\u4f3c\uff0c\u4f46\u5728\u4f7f\u7528\u4e0a\u537b\u6709\u8457\u660e\u986f\u7684\u5dee\u7570\u3002<\/p>\n<h2 id=\"1-%e5%87%bd%e6%95%b8%e6%a6%82%e8%bf%b0-osdRGQllyC\">1. \u51fd\u6578\u6982\u8ff0<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u4f86\u770b\u770b\u9019\u5169\u500b\u51fd\u6578\u7684\u57fa\u672c\u7528\u6cd5\uff1a<\/p>\n<ul>\n<li><code>mysql_fetch_row()<\/code>\uff1a\u6b64\u51fd\u6578\u5f9e\u7d50\u679c\u96c6\u4e2d\u53d6\u5f97\u4e00\u884c\u8cc7\u6599\uff0c\u4e26\u4ee5\u6578\u5b57\u7d22\u5f15\u7684\u5f62\u5f0f\u8fd4\u56de\u4e00\u500b\u6578\u7d44\u3002\u9019\u610f\u5473\u8457\u4f60\u53ea\u80fd\u901a\u904e\u6578\u5b57\u7d22\u5f15\u4f86\u8a2a\u554f\u8cc7\u6599\u3002<\/li>\n<li><code>mysql_fetch_array()<\/code>\uff1a\u6b64\u51fd\u6578\u5247\u66f4\u70ba\u9748\u6d3b\uff0c\u9664\u4e86\u8fd4\u56de\u6578\u5b57\u7d22\u5f15\u7684\u6578\u7d44\u5916\uff0c\u9084\u53ef\u4ee5\u9078\u64c7\u8fd4\u56de\u95dc\u806f\u7d22\u5f15\u7684\u6578\u7d44\u3002\u9019\u4f7f\u5f97\u958b\u767c\u8005\u53ef\u4ee5\u901a\u904e\u6b04\u4f4d\u540d\u7a31\u6216\u6578\u5b57\u7d22\u5f15\u4f86\u8a2a\u554f\u8cc7\u6599\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e4%bd%bf%e7%94%a8%e7%af%84%e4%be%8b-osdRGQllyC\">2. \u4f7f\u7528\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u9019\u5169\u500b\u51fd\u6578\u7684\u4f7f\u7528\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n\/\/ \u9023\u63a5\u5230\u8cc7\u6599\u5eab\n$link = mysql_connect(\"localhost\", \"username\", \"password\");\nmysql_select_db(\"database_name\", $link);\n\n\/\/ \u57f7\u884c\u67e5\u8a62\n$result = mysql_query(\"SELECT id, name FROM users\");\n\n\/\/ \u4f7f\u7528 mysql_fetch_row()\nwhile ($row = mysql_fetch_row($result)) {\n    echo \"ID: \" . $row[0] . \" - Name: \" . $row[1] . \"&lt;br&gt;\";\n}\n\n\/\/ \u91cd\u7f6e\u7d50\u679c\u96c6\nmysql_data_seek($result, 0);\n\n\/\/ \u4f7f\u7528 mysql_fetch_array()\nwhile ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {\n    echo \"ID: \" . $row['id'] . \" - Name: \" . $row['name'] . \"&lt;br&gt;\";\n}\n?&gt;<\/code><\/pre>\n<h2 id=\"3-%e8%bf%94%e5%9b%9e%e5%80%bc%e7%9a%84%e5%b7%ae%e7%95%b0-osdRGQllyC\">3. \u8fd4\u56de\u503c\u7684\u5dee\u7570<\/h2>\n<p>\u5982\u4e0a\u6240\u793a\uff0c<code>mysql_fetch_row()<\/code> \u8fd4\u56de\u7684\u6578\u7d44\u662f\u4ee5\u6578\u5b57\u7d22\u5f15\u70ba\u4e3b\u7684\uff0c\u9019\u610f\u5473\u8457\u4f60\u9700\u8981\u8a18\u4f4f\u6bcf\u500b\u6b04\u4f4d\u7684\u7d22\u5f15\u4f4d\u7f6e\u3002\u800c <code>mysql_fetch_array()<\/code> \u5247\u53ef\u4ee5\u9078\u64c7\u8fd4\u56de\u95dc\u806f\u7d22\u5f15\u7684\u6578\u7d44\uff0c\u9019\u6a23\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u6b04\u4f4d\u540d\u7a31\u4f86\u8a2a\u554f\u8cc7\u6599\uff0c\u9019\u5728\u5927\u578b\u67e5\u8a62\u4e2d\u6703\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n<h2 id=\"4-%e6%80%a7%e8%83%bd%e8%80%83%e9%87%8f-osdRGQllyC\">4. \u6027\u80fd\u8003\u91cf<\/h2>\n<p>\u5728\u6027\u80fd\u65b9\u9762\uff0c<code>mysql_fetch_row()<\/code> \u901a\u5e38\u6703\u6bd4 <code>mysql_fetch_array()<\/code> \u66f4\u5feb\uff0c\u56e0\u70ba\u5b83\u53ea\u8fd4\u56de\u6578\u5b57\u7d22\u5f15\u7684\u6578\u7d44\uff0c\u7701\u53bb\u4e86\u984d\u5916\u7684\u95dc\u806f\u7d22\u5f15\u8655\u7406\u3002\u7136\u800c\uff0c\u9019\u7a2e\u6027\u80fd\u5dee\u7570\u5728\u5927\u591a\u6578\u60c5\u6cc1\u4e0b\u662f\u5fae\u4e0d\u8db3\u9053\u7684\uff0c\u9664\u975e\u5728\u8655\u7406\u5927\u91cf\u8cc7\u6599\u6642\u3002<\/p>\n<h2 id=\"5-%e4%bd%bf%e7%94%a8%e5%bb%ba%e8%ad%b0-osdRGQllyC\">5. \u4f7f\u7528\u5efa\u8b70<\/h2>\n<p>\u5728\u9078\u64c7\u4f7f\u7528\u54ea\u500b\u51fd\u6578\u6642\uff0c\u958b\u767c\u8005\u61c9\u6839\u64da\u5177\u9ad4\u9700\u6c42\u4f86\u6c7a\u5b9a\u3002\u5982\u679c\u4f60\u53ea\u9700\u8981\u7c21\u55ae\u5730\u901a\u904e\u6578\u5b57\u7d22\u5f15\u4f86\u8a2a\u554f\u8cc7\u6599\uff0c<code>mysql_fetch_row()<\/code> \u662f\u4e00\u500b\u4e0d\u932f\u7684\u9078\u64c7\u3002\u7136\u800c\uff0c\u5982\u679c\u4f60\u5e0c\u671b\u901a\u904e\u6b04\u4f4d\u540d\u7a31\u4f86\u63d0\u9ad8\u53ef\u8b80\u6027\u548c\u53ef\u7dad\u8b77\u6027\uff0c\u5247\u61c9\u9078\u64c7 <code>mysql_fetch_array()<\/code>\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-osdRGQllyC\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u7684\u4f86\u8aaa\uff0c<code>mysql_fetch_row()<\/code> \u548c <code>mysql_fetch_array()<\/code> \u90fd\u662f\u5f9e MySQL \u67e5\u8a62\u7d50\u679c\u4e2d\u63d0\u53d6\u8cc7\u6599\u7684\u6709\u6548\u5de5\u5177\u3002\u9078\u64c7\u54ea\u4e00\u500b\u51fd\u6578\u53d6\u6c7a\u65bc\u4f60\u7684\u5177\u9ad4\u9700\u6c42\u548c\u4f7f\u7528\u60c5\u5883\u3002\u4e86\u89e3\u9019\u4e9b\u5dee\u7570\u5c07\u6709\u52a9\u65bc\u958b\u767c\u8005\u5728\u9032\u884c\u8cc7\u6599\u5eab\u64cd\u4f5c\u6642\u505a\u51fa\u66f4\u660e\u667a\u7684\u9078\u64c7\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u7db2\u7ad9\u9084\u662f\u5927\u578b\u61c9\u7528\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 MySQL_FETCH_ROW() \u548c MySQL_FETCH_ARRAY() \u7684\u4e3b\u8981\u5dee\u7570\uff0c\u63a2\u7d22\u5b83\u5011\u5728\u6578\u64da\u63d0\u53d6\u4e2d\u7684\u4e0d\u540c\u7528\u6cd5\u548c\u6027\u80fd\u5f71\u97ff\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-75680","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75680","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=75680"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75680\/revisions"}],"predecessor-version":[{"id":75681,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75680\/revisions\/75681"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=75680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=75680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=75680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}