{"id":487,"date":"2010-08-03T20:15:48","date_gmt":"2010-08-03T20:15:48","guid":{"rendered":""},"modified":"2010-08-03T20:15:48","modified_gmt":"2010-08-03T20:15:48","slug":"487","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=487","title":{"rendered":"\u5173\u4e8ephp\u4f18\u5316\u7684\u6545\u4e8b-\u8f6c"},"content":{"rendered":"<p>\u516c\u53f8\u6709\u51e0\u4e2a\u7f51\u7ad9\u642d\u5728\u7f8e\u56fd\u7684\u865a\u62df\u4e3b\u673a\u4e0a\uff0c\u670d\u52a1\u5668\u4e0a\u7684mysql\u670d\u52a1\u5dee\u4e0d\u591a\u6bcf\u4e00\u5929\u90fd\u4f1a\u7a81\u7136\u4e0d\u77e5\u4ec0\u4e48\u65f6\u5019\u6302\u6389\uff0c\u7136\u540e\u8fc7\u4e00\u4f1a\u53c8\u6062\u590d\u4e86\uff0c\u6000\u7591\u662f\u8d85\u51facpu\u7684\u4f7f\u7528\u9650\u5236\u800c\u88ab\u81ea\u52a8\u7ed3\u675f\u4e86\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u8be5\u670d\u52a1\u5668\u4e0a\u7684\u6d41\u91cf\u5f88\u5c0f\u3002\u4e8e\u662f\u65e9\u5148\u7684\u65f6\u5019\u8054\u7cfb\u4e86\u670d\u52a1\u5668\u63d0\u4f9b\u5546\u7684\u5370\u5ea6\u963f\u4e09\u5ba2\u670d\uff0c\u60f3\u770b\u770b\u662f\u4e0d\u662f\u5176\u4ed6\u7528\u6237\u641e\u591a\u4e86\u5bb3\u7684\u5927\u5bb6\u4e00\u8d77\u6b7b\uff0c\u963f\u4e09\u4eec\u67e5\u627e\u4e86\u4e4b\u540e\uff0c\u4fe1\u8a93\u65e6\u65e6\u7684\u62cd\u7740\u957f\u6bdb\u7684\u80f8\u90e8\u4fdd\u8bc1\u4e0d\u662f\u4ed6\u4eec\u7684\u95ee\u9898\uff0c\u4e8b\u60c5\u6ca1\u6709\u89e3\u51b3\u3002\u60ac\u7740\u4e0d\u662f\u4e2a\u4e8b\uff0c\u53ea\u597d\u81ea\u5df1\u67e5\u4e86\uff0c\u597d\u5728\u53ef\u4ee5\u8bbf\u95ee\u5230information_schema\u5e93\uff0c\u770b\u4e86\u770b\uff0c\u6ca1\u8bdd\u4e86\uff0cuser_statistics\u91cc\u9762\u7684\u6570\u636e\u663e\u793a\u6211\u4eec\u7684\u4e00\u4e2amysql\u7528\u6237\u5728busy_time\uff0ccpu_time\u7b49\u6307\u6807\u4e0a\u90fd\u9ad8\u5230\u4e0d\u884c\uff0c\u81ea\u5df1\u7684\u4e8b\uff0c\u597d\u5728\u963f\u4e09\u6ca1\u6709\u53d1\u73b0\u3002\u4e8e\u662f\u8d76\u7d27\u67e5\u7a0b\u5e8f\uff0c\u4e4b\u524d\u7684\u8fd9\u4e2a\u7f51\u7ad9\u7a0b\u5e8f\u4e0d\u662f\u7531\u6211\u505a\u7684\uff0c\u4f46\u662f\u77e5\u9053\u91cc\u9762\u95ee\u9898\u5f88\u591a\uff0c\u67b6\u6784\u5230\u5b9e\u73b0\u90fd\u6709\u95ee\u9898\uff0c\u4f46\u662f\u9875\u9762\u4e0d\u662f\u4e00\u822c\u7684\u591a\uff0c\u4ee3\u7801\u5939\u6742\u7740html\uff0c\u5168\u770b\u8fc7\u53bb\u8fd8\u4e0d\u6b7b\uff0c(\u8fd9\u79cd\u65f6\u5019\u5c31\u5c24\u4e3a\u7684\u89c9\u7740mvc\u591a\u7f8e\u5999)\uff0c\u5e73\u65f6\u80fd\u51d1\u5408\u7740\u8fd0\u884c\u5c31\u53ef\u4ee5\u4e86\uff0c\u53cd\u6b63\u6ca1\u6709\u4ec0\u4e48\u8bbf\u95ee\u91cf\u3002<\/p>\n<p>\u65e2\u7136\u662fmysql\u7684\u8d1f\u62c5\u91cd\uff0c\u90a3\u5c31\u5148\u627e\u8fd9\u4e2a\uff0c\u672c\u5730\u4e0a\u641e\u4e00\u4e2a\u7f51\u7ad9\u7684\u955c\u50cf\u8fd0\u884c\u4e0b\uff0c\u5728my.ini\u91cc\u4fee\u6539\u6dfb\u52a0<\/p>\n<p><code><br \/>[mysqld]<br \/>log=\"d:\/temp\/mysql.log\"<br \/>log_slow_queries=\"d:\/temp\/mysql_slow.log\"<br \/>long_query_time=1<br \/><\/code><\/p>\n<p>\u8fd9\u4e2a\u76ee\u5f55\u662f\u8981\u5df2\u7ecf\u5b58\u5728\u7684\u3002\u91cd\u542fmysql\u670d\u52a1\uff0c\u5c31\u53ef\u4ee5\u8bb0\u5f55\u4e86\u3002<\/p>\n<p>\u67e5\u770bsql\u8bb0\u5f55\u540e\u5927\u5403\u4e00\u60ca\uff0c\u67e5\u8be2\u7684\u6570\u91cf\u60ca\u4eba\uff0c\u968f\u4fbf\u4e00\u4e2a\u9875\u9762\uff0csql\u67e5\u8be2\u90fd\u5728\u51e0\u5341\u6761\uff0c\u591a\u7684\u6709\u4e0a\u5343\u6761\uff01<\/p>\n<p>\u4ee5\u8bba\u575b\u6765\u8bf4\u5427\uff0c\u4e00\u4e2a\u9875\u9762\u7684\u6570\u636e\u5e93\u67e5\u8be2\u6b21\u6570\u4e5f\u5c31\u662f10\u6b21\u4e00\u4e0b\uff0c\u7528\u4e86\u7f13\u5b58\u7684\u8fd8\u53ef\u4ee5\u518d\u4f4e\u3002\u8fd9\u6837\u7b97\u7684\u8bdd\uff0c\u5c31\u76f8\u5f53\u4e8e\u539f\u6765\u51e0\u5341\u500d\u7684\u8d1f\u62c5\uff0c\u80fd\u4e0d\u6302\uff1f<\/p>\n<p>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select * FROM pz_content Where uid=19 and sec_id=10 and aid=688 and pic_url&lt;&gt;&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select * from pz_area where aid=688&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select * FROM pz_content Where uid=19 and sec_id=10 and aid=689 and pic_url&lt;&gt;&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select * from pz_area where aid=689&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select * FROM pz_content Where uid=19 and sec_id=10 and aid=690 and pic_url&lt;&gt;&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select * from pz_area where aid=690&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select * FROM pz_content Where uid=19 and sec_id=10 and aid=691 and pic_url&lt;&gt;&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select * from pz_area where aid=691&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select * FROM pz_content Where uid=19 and sec_id=10 and aid=692 and pic_url&lt;&gt;&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select * from pz_area where aid=692&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select * FROM pz_content Where uid=19 and sec_id=10 and aid=693 and pic_url&lt;&gt;&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select * from pz_area where aid=693&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select * FROM pz_content Where uid=19 and sec_id=10 and aid=694 and pic_url&lt;&gt;&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>14 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select * from pz_area where aid=694<\/p>\n<p>\u8c01\u4eba\u4e5f\u4e0d\u80fd\u90a3\u8fb9\u6709\u6bc5\u529b\u5199\u4e0b\u4e0a\u767e\u6761\u7684\u67e5\u8be2\u554a\uff0c\u6240\u4ee5\u80af\u5b9a\u662f\u5faa\u73af\u67e5\u8be2\u3002sql\u8bed\u53e5\u4e5f\u8868\u660e\u8fd9\u4e00\u70b9\u3002\u77e5\u9053\u539f\u56e0\u4e86\u5c31\u597d\u6539\u4e86\uff0c\u627e\u5230\u76f8\u5173\u9875\u9762\uff0c\u6539\u6389\u5faa\u73af\u67e5\u8be2\uff0c\u4f8b\u5982\uff0c\u6709\u4e00\u4e2a\u9875\u9762\uff0c\u8981\u663e\u793a\u6240\u6709\u5730\u533a\u5206\u7c7b\u548c\u8be5\u5206\u7c7b\u4e0b\u7684\u6587\u7ae0\u6570\uff0c\u5148\u4e0d\u8003\u8651\u6570\u636e\u5e93\u7684\u7ed3\u6784\u4f18\u5316\uff0c\u5c31\u7a0b\u5e8f\u800c\u8a00\uff0c\u539f\u6765\u7684\u5927\u6982\u662f\u8fd9\u6837\u5b50\u7684<\/p>\n<p><code><br \/>$sql1=\"Select aid,count(*) as cc FROM pz_content Where uid=$uid group by aid\";<br \/>$rs1=$db-&gt;query($sql1);<br \/>if(is_array($rs1)){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach($rs1 as $r1){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8f93\u51fa...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo id2name($r1-&gt;aid);<br \/>&nbsp;&nbsp;&nbsp;&nbsp; } }<br \/>............<br \/>function&nbsp;&nbsp;id2name($aid){<br \/>&nbsp;&nbsp;&nbsp;&nbsp;$sql=\"select ename from pz_area_a where aid_a=\".$id;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;$result=mysql_query($sql);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;$row=mysql_fetch_object($result);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;return $row-&gt;ename;<br \/>}<br \/><\/code><br \/>\u5148\u4e0d\u7ba1\u4ee3\u7801\u7684\u5bb9\u9519\uff0c\u770b\u5b9e\u73b0\u5c31\u77e5\u9053\uff0c\u4ed6\u5148\u8bfb\u53d6\u4e86\u8be5\u7528\u6237\u7684\u76f8\u5173\u6587\u7ae0\u5e76\u6309\u5730\u533aID\u8fdb\u884c\u4e86\u5206\u7ec4\u548c\u7edf\u8ba1\u4e2a\u6570\uff0c\u7136\u540e\u518d\u6bcf\u4e2a\u5730\u533a\u6bcf\u4e2a\u5730\u533a\u5730\u8f93\u51fa\u5730\u533a\u540d\u5b57\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u67091w\u4e2a\u5730\u533a\uff0c\u8fd9\u91cc\u5c31\u8981\u67e5\u8be21w\u6b21\u3002\u653e\u4e0a\u4e00\u4e2a\u8ba1\u65f6\u7684\u4ee3\u7801\uff0c\u770b\u4e86\u4e0b\uff0c\u5927\u6982\u8017\u7528\u5185\u5b586M\uff0c\u6267\u884c\u65f6\u95f416\u79d2\uff0c\u7d2f\u8ba1\u67e5\u8be21001\u6b21<\/p>\n<p>\u5176\u5b9e\uff0c\u8fd9\u91cc\u662f\u53ea\u8981\u7528\u4e00\u53e5sql\u5c31\u53ef\u4ee5\u641e\u5b9a\u7684\u4e8b\u60c5\uff0c\u5e76\u4e0d\u9700\u8981\u5faa\u73af\u3002<\/p>\n<p><code><br \/>$sql1=\"select pz_area.aid,pz_area.ename,tb1.cc from pz_area right join (Select aid,count(*) as cc FROM pz_content Where uid=$uid group by aid) as tb1 on pz_area.aid=tb1.aid\";<br \/>$rs1=$db-&gt;query($sql1);<br \/>if(is_array($rs1)){<br \/>\u3000\u3000foreach($rs1 as $r1){<br \/>\u8f93\u51fa...<br \/>\u3000\u3000 echo $r1-&gt;ename;<br \/>\u3000\u3000}}<br \/><\/code><br \/>\u95ee\u9898\u5c31\u53ef\u4ee5\u89e3\u51b3\u4e86\u3002\u91cd\u65b0\u8fd0\u884c\u4e0b\uff0c\u5185\u5b58\u8017\u7528\u5dee\u4e0d\u591a\uff0c\u67e5\u8be21\u6b21\uff0cCPU\u6267\u884c\u65f6\u95f4\u53ea\u6709647\u6beb\u79d2\uff0c\u548c\u539f\u6765\u7684\u5dee\u4e8626\u500d\uff01\u518d\u770b\u4e00\u4e0b\uff0c\u53d1\u73b0\u8fd9\u4e2apz_content\u7684\u8868\uff0c\u8bb0\u5f55\u8fd8\u7b97\u6bd4\u8f83\u591a\u7684\uff0c\u6709\u7ecf\u5e38\u8981\u6309\u5730\u533a\u67e5\u8be2\u5212\u5206\u4e4b\u7c7b\u7684\uff0c\u4f46\u662f\u539f\u6765\u4ec0\u4e48\u7d22\u5f15\u4e5f\u6ca1\u6709\u3002\u987a\u9053\u5728aid\u4e0a\u52a0\u4e0a\u4e00\u4e2a\u7d22\u5f15\uff0c\u6267\u884c\u65f6\u95f4\u7f29\u77ed\u5230432\u6beb\u79d2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u516c\u53f8\u6709\u51e0\u4e2a\u7f51\u7ad9\u642d\u5728\u7f8e\u56fd\u7684\u865a\u62df\u4e3b\u673a\u4e0a\uff0c\u670d\u52a1\u5668\u4e0a\u7684mysql\u670d\u52a1\u5dee\u4e0d\u591a\u6bcf&#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-487","post","type-post","status-publish","format-standard","hentry","category-Php"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/487","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=487"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/487\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}