{"id":581,"date":"2010-12-30T17:21:51","date_gmt":"2010-12-30T17:21:51","guid":{"rendered":""},"modified":"2010-12-30T17:21:51","modified_gmt":"2010-12-30T17:21:51","slug":"581","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=581","title":{"rendered":"\u5173\u4e8e\u5728PHP\u5f00\u53d1\u4e2d\u56db\u79cd\u67e5\u8be2\u8fd4\u56de\u7ed3\u679c\u5206\u6790"},"content":{"rendered":"<p>1.&lt;!&#8211;\u4f7f\u7528mysql_result()\u6765\u83b7\u53d6\u6570\u636e&#8211;&gt;<br \/><code><br \/>&lt;?php<br \/>$connection=mysql_connect(\"localhost\",\"root\",\"password\"); \/\/\u8fde\u63a5\u5e76\u9009\u62e9\u6570\u636e\u5e93\u670d\u52a1\u5668<br \/>mysql_select_db(\"test\",$connection);<br \/>$query=\"insert into users(user_name)\"; \/\/\u5728test\u6570\u636e\u5e93\u91cc\u63d2\u5165\u4e00\u6761\u6570\u636e<br \/>$query.=\"values('tuxiaohui')\";<br \/>$result=mysql_query($query);<br \/>if(!$query)<br \/>echo \"insert data failed!&lt;br&gt;\";<br \/>else{<br \/>$query=\"select * from users\"; \/\/\u67e5\u8be2\u6570\u636e<br \/>$result=mysql_query($query,$connection);<br \/>for($rows_count=0;$rows_count&lt;7;$rows_count++) \/\/\u7528mysql_result\u83b7\u5f97\u6570\u636e\u5e76\u8f93\u51fa\uff0cmysql_result() \u8fd4\u56de MySQL \u7ed3\u679c\u96c6\u4e2d\u4e00\u4e2a\u5355\u5143\u7684\u5185\u5bb9\u3002<br \/>{<br \/>&nbsp;&nbsp; echo \"\u7528\u6237ID\uff1a\".mysql_result($result,$rows_count,\"user_id\").\"&lt;br&gt;\";<br \/>&nbsp;&nbsp; echo \"\u7528\u6237\u540d\uff1a\".mysql_result($result,$rows_count,\"user_name\").\"&lt;br&gt;\";<br \/>}<br \/>}<br \/>?&gt;<br \/><\/code><\/p>\n<p>2.&lt;!&#8211;\u4f7f\u7528mysql_fetch_row()\u6765\u83b7\u53d6\u6570\u636e,\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8fd4\u56de\u67e5\u8be2\u7ed3\u679c&#8211;&gt;<br \/><code><br \/>&lt;?php<br \/>$connection=mysql_connect(\"localhost\",\"root\",\"password\"); \/\/\u8fde\u63a5\u5e76\u9009\u62e9\u6570\u636e\u5e93\u670d\u52a1\u5668<br \/>mysql_select_db(\"test\",$connection);<br \/>$query=\"select * from users\";<br \/>$result=mysql_query($query,$connection);<br \/>while($row=mysql_fetch_row($result))<br \/>{<br \/>echo \"\u7528\u6237ID\uff1a\".$row[0].\"&lt;br&gt;\";<br \/>echo \"\u7528\u6237\u540d\uff1a\".$row[1].\"&lt;br&gt;\";<br \/>}<br \/>?&gt;<br \/><\/code><\/p>\n<p>3.&lt;!&#8211;\u4f7f\u7528mysql_fetch_array()\u6765\u83b7\u53d6\u6570\u636e,\u540cmysql_fetch_row()\u7c7b\u4f3c\uff0c\u4e5f\u662f\u83b7\u53d6\u7ed3\u679c\u96c6\u4e2d\u5f53\u524d\u884c\u6570\u636e\uff0c\u5e76\u5728\u8c03\u7528\u540e\u81ea\u52a8\u6ed1\u5411\u4e0b\u4e00\u884c&#8211;&gt;<br \/><code><br \/>&lt;?php<br \/>$connection=mysql_connect(\"localhost\",\"root\",\"password\"); \/\/\u8fde\u63a5\u5e76\u9009\u62e9\u6570\u636e\u5e93\u670d\u52a1\u5668<br \/>mysql_select_db(\"test\",$connection);<br \/>$query=\"select * from users\";<br \/>$result=mysql_query($query,$connection);<br \/>while($row=mysql_fetch_array($result))<br \/>{<br \/>echo \"\u7528\u6237ID\uff1a\".$row[0].\"&lt;br&gt;\";&nbsp;&nbsp; \/\/\u4e5f\u53ef\u4ee5\u5199\u505a$row[\"user_id\"]<br \/>echo \"\u7528\u6237\u540d\uff1a\".$row[1].\"&lt;br&gt;\"; \/\/\u4e5f\u53ef\u4ee5\u5199\u505a$row[\"user_name\"]<br \/>}<br \/>?&gt;<br \/><\/code><\/p>\n<p>4.&lt;!&#8211;\u4f7f\u7528mysql_fetch_object()\u4ee5\u5bf9\u8c61\u7684\u5f62\u5f0f\u8fd4\u56de\u67e5\u8be2\u7ed3\u679c\uff0c\u4e5f\u662f\u7528\u4e8e\u67e5\u8be2\u6570\u636e\u7ed3\u679c\u96c6\uff0c\u8fd4\u56de\u5f53\u524d\u884c\u6570\u636e\uff0c\u5e76\u81ea\u52a8\u6ed1\u5411\u4e0b\u4e00\u884c\uff0c\u4e0d\u540c\u7684\u662f\u5b83\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u96c6\u5408\u5373\u4e3a\u6570\u636e\u7684\u5c5e\u6027\u96c6\u5408\uff0c\u800c\u5c5e\u6027\u4e0a\u7684\u503c\u5219\u4e3a\u6570\u636e\u5e93\u4e2d\u5f53\u524d\u884c\u8be5\u5c5e\u6027\u4e0a\u7684\u503c&#8211;&gt;<br \/><code><br \/>&lt;?php<br \/>$connection=mysql_connect(\"localhost\",\"root\",\"root\"); \/\/\u8fde\u63a5\u5e76\u9009\u62e9\u6570\u636e\u5e93\u670d\u52a1\u5668<br \/>mysql_select_db(\"test\",$connection);<br \/>$query=\"select * from users\";<br \/>$result=mysql_query($query,$connection);<br \/>while($row=mysql_fetch_object($result))<br \/>{<br \/>echo \"\u7528\u6237ID\uff1a\".$row-&gt;user_id.\"&lt;br&gt;\"; \/\/\u901a\u8fc7\u5bf9\u8c61\u8fd0\u7b97\u7b26-&gt;\u83b7\u5f97\u6539\u884c\u6570\u636e\u5728\u5176\u5c5e\u6027\u4e0a\u7684\u503c\u3002<br \/>echo \"\u7528\u6237\u540d\uff1a\".$row-&gt;user_name.\"&lt;br&gt;\";<br \/>}<br \/>?&gt;<br \/><\/code><\/p>\n<p>5.\u7efc\u5408\u6bd4\u8f83\uff1a<\/p>\n<p>mysql_result()\uff1a\u4f18\u70b9\u5728\u4e8e\u4f7f\u7528\u65b9\u4fbf\uff1b\u5176\u7f3a\u70b9\u5728\u4e8e\u529f\u80fd\u5c11\uff0c\u4e00\u6b21\u8c03\u7528\u53ea\u80fd\u83b7\u53d6\u7ed3\u679c\u6570\u636e\u96c6\u4e2d\u7684\u4e00\u884c\u5143\u7d20\uff0c\u5bf9\u8f83\u5927\u578b\u7684\u6570\u636e\u5e93\u6548\u7387\u8f83\u4f4e\uff1b<\/p>\n<p>mysql_fetch_row()\uff1a\u4f18\u70b9\u5728\u4e8e\u6267\u884c\u6548\u7387\u57284\u79cd\u65b9\u6cd5\u4e2d\u6700\u9ad8\uff1b\u4e0d\u8db3\u5728\u4e8e\u53ea\u80fd\u7528\u6570\u5b57\u4f5c\u4e3a\u5c5e\u6027\u7d22\u5f15\u6765\u83b7\u5f97\u5c5e\u6027\u503c\uff0c\u5728\u4f7f\u7528\u65f6\u975e\u5e38\u5bb9\u6613\u51fa\u73b0\u6df7\u6dc6\uff1b<\/p>\n<p>mysql_fetch_array()\uff1a\u6267\u884c\u6548\u7387\u540c\u6837\u9ad8\uff0c\u540cmysql_fetch_row()\u76f8\u5dee\u65e0\u51e0\uff0c\u5e76\u754c\u53ef\u4ee5\u7528\u5c5e\u6027\u540d\u65b9\u5f0f\u76f4\u63a5\u83b7\u5f97\u5c5e\u6027\u503c\uff0c\u56e0\u6b64\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u6700\u5e38\u7528\uff1b<\/p>\n<p>mysql_fetch_object()\uff1a\u91c7\u7528\u4e86\u9762\u5411\u5bf9\u8c61\u601d\u60f3\uff0c\u5728\u8bbe\u8ba1\u601d\u8def\u4e0a\u66f4\u4e3a\u5148\u8fdb\uff0c\u5982\u679c\u4e60\u60ef\u4e8e\u7528\u9762\u5411\u5bf9\u8c61\u7684\u601d\u8def\u6765\u5199\u7a0b\u5e8f\uff0c\u5219\u4f1a\u5f88\u81ea\u5730\u9009\u62e9\u5b83\u3002\u5176\u6b21\uff0c\u8be5\u65b9\u6cd5\u7684\u4f18\u70b9\u8fd8\u4f53\u73b0\u5728\uff0c\u5bf9\u4e8e\u7ed3\u6784\u8f83\u4e3a\u8d1f\u8d23\u7684\u6570\u636e\u7ed3\u679c\uff0c\u5728\u903b\u8f91\u4e0a\u66f4\u4e3a\u6e05\u6670\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.&lt;!&#8211;\u4f7f\u7528mysql_result()\u6765\u83b7\u53d6\u6570&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-Php"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=581"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/581\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}