{"id":1710,"date":"2018-03-13T11:25:00","date_gmt":"2018-03-13T03:25:00","guid":{"rendered":"http:\/\/39.100.100.179\/?p=1710"},"modified":"2018-03-13T11:47:42","modified_gmt":"2018-03-13T03:47:42","slug":"php%e6%93%8d%e4%bd%9cmysql%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e6%8e%92%e8%a1%8c%e6%a6%9c%ef%bc%88windows%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=1710","title":{"rendered":"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09"},"content":{"rendered":"<h2>\u4e00\u3001\u6761\u4ef6<\/h2>\n<p>1.\u672c\u6559\u7a0b\u4f7f\u7528\u7684\u73af\u5883\u662fWAMP\uff0c\u9644\u4e0a\u73af\u5883\u5b89\u88c5\u6559\u7a0b<a href=\"https:\/\/jingyan.baidu.com\/article\/4b52d702cb7792fc5c774bed.html\" target=\"_blank\">WAMP\u5b89\u88c5\u6559\u7a0b<\/a><\/p>\n<p>2.\u5b8c\u6210php\u73af\u5883\u6d4b\u8bd5\uff0c\u80fd\u591f\u6b63\u5e38\u6253\u5f00php\u9875\u9762\uff0c\u8be6\u89c1<a href=\"http:\/\/www.u3d8.com\/?p=1597\">http:\/\/www.u3d8.com\/?p=1597<\/a>\u00a0 \uff08\u53ea\u9700\u6d4b\u8bd5\u524d\u4e24\u6b65\u9aa4\u5373\u53ef\uff09<\/p>\n<p>3.\u672c\u6559\u7a0b\u4f7f\u7528\u7684MySqlHelper\u7c7b\u6765\u5bf9\u6570\u636e\u5e93\u7684\u589e\u5220\u6539\u67e5\uff0c\u5177\u4f53\u64cd\u4f5c\u8bf7\u89c1\uff1a<a href=\"http:\/\/www.u3d8.com\/?p=1606\">http:\/\/www.u3d8.com\/?p=1606<\/a><\/p>\n<p>\u5f53\u4e0a\u9762\u4e09\u4e2a\u6559\u7a0b\u90fd\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u7ee7\u7eed\u672c\u6559\u7a0b\u7684\u5b66\u4e60\u3002<\/p>\n<h2>\u4e8c\u3001\u521b\u5efa\u6570\u636e\u8868<\/h2>\n<p>\u6253\u5f00<em><strong>phpMyAdmin<\/strong><\/em>\uff0c\u6dfb\u52a0<em><strong>test<\/strong><\/em>\u6570\u636e\u5e93\u540d\u79f0\u3001<em><strong>rank<\/strong><\/em>\u6570\u636e\u8868<\/p>\n<p>\u6839\u636e\u4e0b\u56fe\uff0c\u5728rank\u6570\u636e\u8868\u91cc\u6dfb\u52a0\u4e24\u6761\u5b57\u6bb5<\/p>\n<p><img title=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" loading=\"lazy\" class=\"size-full wp-image-1711 alignnone\" src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313105517.png\" width=\"1321\" height=\"305\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313105517.png 1321w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313105517-300x69.png 300w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313105517-768x177.png 768w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313105517-1024x236.png 1024w\" sizes=\"(max-width: 1321px) 100vw, 1321px\" \/><\/p>\n<h2>\u4e09\u3001\u4fee\u6539MySqlHelper.php<\/h2>\n<pre class=\"lang:php decode:true\">    define('DB_DBNAME', 'test');<\/pre>\n<h2>\u56db\u3001\u65b0\u5efa\u6392\u884c\u699c\u811a\u672c<\/h2>\n<p>\u5728MySqlHelper.php\u540c\u7ea7\u76ee\u5f55\u65b0\u5efa<em>ranklist.php<\/em>\u811a\u672c<\/p>\n<pre class=\"lang:php decode:true \">&lt;?php\r\n\trequire_once 'MySqlHelper.php';  \r\n\t\r\n\t\/\/echo json_encode($data);\t\t\/\/ \u8f6c\u6210json\u8f93\u51fa\r\n\t\r\n\t$db = new MySqlHelper();  \r\n\t\r\n\t\/\/ \u8fde\u63a5\u6570\u636e\u5e93\r\n        $link = $db-&gt;connect();  \r\n        \/\/print_r($link); \r\n\t\r\n\t\/\/ \u8868\u540d\u79f0\r\n\t$table = \"rank\";\t\/\/ \u5bf9\u5e94\u81ea\u5df1\u8981\u64cd\u4f5c\u7684\u8868\u540d\u79f0\r\n\t\r\n\t\/\/ \u67e5\u627e\u6240\u6709\u6570\u636e\r\n\t$sqlDatas = array();\r\n\t$sql=\"SELECT * FROM {$table}\"; \r\n\t$sqlDatas = $db-&gt;fetchAll($sql);\r\n\t\r\n\t\/\/ \u901a\u8fc7name \u67e5\u627e\u5bf9\u5e94\u6570\u7ec4\u5143\u7d20\r\n\r\n\t$searchValue = $_GET[\"name\"];\r\n\tif($sqlDatas != null)\r\n\t\t$searchResult = array_filter($sqlDatas, function($t) use ($searchValue) { return $t['name'] == $searchValue; });\r\n\t\/\/ \u5982\u679c\u6ca1\u6709\u8fd9\u4e2aname\uff0c\u5219\u65b0\u589e\u52a0\r\n\tif($sqlDatas == null || count($searchResult) == 0)\t\t\t\r\n\t{\r\n\t\t$db-&gt;insert($_GET, $table);\t\t\r\n\t\t$sql=\"SELECT * FROM {$table}\"; \r\n\t\t$sqlDatas = $db-&gt;fetchAll($sql);\t\t\r\n\t}\r\n\t\/\/ \u5982\u679c\u5df2\u6709\u8fd9\u4e2aname\uff0c\u4e14\u6700\u65b0\u5206\u6570\u9ad8\u4e8e\u5386\u53f2\u5f97\u5206\uff0c\u5219\u66f4\u65b0\u6570\u636e\u5e93\r\n\telse if($_GET[\"score\"] &gt; current(array_values($searchResult))[\"score\"])\t\r\n\t{\r\n\t\t$db-&gt;update($_GET, $table, 'name=\"'.$_GET[\"name\"].'\"');\r\n\t}\r\n\t\r\n\t$sql=\"SELECT * FROM {$table}\"; \r\n\t$sqlDatas = $db-&gt;fetchAll($sql);\r\n\t\t\r\n\t\/\/ \u6839\u636escore\u6392\u5e8f\r\n\tforeach ( $sqlDatas as $key =&gt; $row ){\r\n                 $score[$key] = $row ['score'];\r\n        }\r\n        array_multisort($score, SORT_DESC, $sqlDatas);\r\n        \/\/var_dump($sqlDatas);\r\n\t\r\n\t\/\/ \u83b7\u53d6\u6392\u540d\r\n\t$searchResult = array_filter($sqlDatas, function($t) use ($searchValue) { return $t['name'] == $searchValue; });\r\n\t$rank = array_keys($sqlDatas,current(array_values($searchResult)),true)[0] + 1;\r\n\tclass FeedBack{\r\n\t\tpublic $rank;\r\n\t\tpublic $all;\r\n\t}\r\n\t$feedBack = new FeedBack();\r\n\t$feedBack-&gt;rank = $rank;\r\n\t$feedBack-&gt;all = count($sqlDatas);\r\n\t\/\/ \u7ed9\u5ba2\u6237\u7aef\u8fd4\u56de\u6392\u540d\r\n\techo json_encode($feedBack);\r\n\t\r\n\t\/\/ \u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5\r\n\t$db-&gt;close($link);\r\n?&gt;<\/pre>\n<h2>\u4e94\u3001\u6d4b\u8bd5\u6392\u884c\u699c<\/h2>\n<p>\u56e0\u4e3aranklist.php\u4e2d\u4f7f\u7528\u7684\u662fGET\u63a5\u6536\u6d88\u606f\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5728\u5730\u5740\u680f\u8fdb\u884c\u6d4b\u8bd5<\/p>\n<p>\u5728\u6d4f\u89c8\u5668\u6253\u5f00<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/localhost\/test\/ranklist.php?name=wangchong1&amp;score=100<\/pre>\n<p>\u67e5\u770b\u8f93\u51fa\u7ed3\u679c<\/p>\n<p><img title=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c2\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c2\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" loading=\"lazy\" class=\"size-full wp-image-1712 alignnone\" src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313111632.png\" width=\"574\" height=\"115\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313111632.png 574w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313111632-300x60.png 300w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/p>\n<p>\u7ee7\u7eed\u6d4b\u8bd5<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/localhost\/test\/ranklist.php?name=wangchong2&amp;score=80<\/pre>\n<p>\u67e5\u770b\u8f93\u51fa\u7ed3\u679c<\/p>\n<p><img title=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c3\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c3\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" loading=\"lazy\" class=\"size-full wp-image-1713 alignnone\" src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313111742.png\" width=\"584\" height=\"97\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313111742.png 584w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313111742-300x50.png 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/p>\n<p>\u7ee7\u7eed\u6d4b\u8bd5<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/localhost\/test\/ranklist.php?name=wangchong3&amp;score=90<\/pre>\n<p>\u67e5\u770b\u8f93\u51fa\u7ed3\u679c<\/p>\n<p><img title=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c4\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Php\u64cd\u4f5cMySql\u5b9e\u73b0\u7b80\u5355\u6392\u884c\u699c\uff08Windows\uff09 - \u7b2c4\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" loading=\"lazy\" class=\"size-full wp-image-1719 alignnone\" src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313112939.png\" width=\"558\" height=\"104\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313112939.png 558w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2018\/03\/QQ\u622a\u56fe20180313112939-300x56.png 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u7ed3\u675f\u8bed<\/h2>\n<p>\u8fd9\u91cc\u5df2\u7ecf\u5b9e\u73b0\u4e86\u6392\u884c\u699c\u7684\u57fa\u7840\u529f\u80fd\uff0c\u5927\u5bb6\u53ef\u4ee5\u5728\u6b64\u57fa\u7840\u8fdb\u884c\u4ee3\u7801\u4f18\u5316\u4ee5\u53ca\u8865\u5145\u81ea\u5df1\u9700\u8981\u5185\u5bb9\u3002<\/p>\n<p>\u672c\u6559\u7a0b\u4ec5\u4f9b\u81ea\u884c\u5b66\u4e60\uff0c\u6d4b\u8bd5\u4f7f\u7528\u3002\u5546\u4e1a\u9879\u76ee\u4e2d\uff0c\u4e0d\u8981\u9891\u7e41\u8bbf\u95ee\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528Redis\\Memcached\u6765\u505a\u6570\u636e\u7f13\u5b58<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6761\u4ef6 1.\u672c\u6559\u7a0b\u4f7f\u7528\u7684\u73af\u5883\u662fWAMP\uff0c\u9644\u4e0a\u73af\u5883\u5b89\u88c5\u6559\u7a0bWAMP\u5b89\u88c5\u6559\u7a0b 2. &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=1710\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[343],"tags":[357],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1710"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1710"}],"version-history":[{"count":9,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1710\/revisions"}],"predecessor-version":[{"id":1725,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1710\/revisions\/1725"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1710"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}