国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

php+mysql prepare 與普通查詢的性能對(duì)比實(shí)例講解

2024-07-24 12:53:13
字體:
供稿:網(wǎng)友

php+mysql prepare 與普通查詢的性能對(duì)比

實(shí)例代碼如下:

<?php class timer { public $StartTime = 0; public $StopTime = 0; public $TimeSpent = 0; function start(){ $this->StartTime = microtime(); } function stop(){ $this->StopTime = microtime(); } function spent() { if ($this->TimeSpent) { return $this->TimeSpent; } else { // http://www.manongjc.com $StartMicro = substr($this->StartTime,0,10); $StartSecond = substr($this->StartTime,11,10); $StopMicro = substr($this->StopTime,0,10); $StopSecond = substr($this->StopTime,11,10); $start = floatval($StartMicro) + $StartSecond; $stop = floatval($StopMicro) + $StopSecond; $this->TimeSpent = $stop - $start; return round($this->TimeSpent,8).'秒'; } } } $timer = new timer; $timer->start(); $mysql = new mysqli('localhost','root','root','ganbaobao_ucenter'); /* $query = $mysql->query("select username,email from uc_members where uid < 100000"); $result = array(); http://www.manongjc.com/article/1194.htmlwhile($result = $query->fetch_array()) { $result[] = array('name'=>$result['username'],'email'=>$result['email']); } */ $query_prepare = $mysql->prepare("select username,email from uc_members where uid < ?"); $id = 100000; $query_prepare->bind_param("i",$id); $query_prepare->execute(); $query_prepare->bind_result($username,$email); $result = array(); while($query_prepare->fetch()) { $result[] = array('name'=>$username,'email'=>$email); } $timer->stop(); echo '</br>預(yù)查詢mysql運(yùn)行100000條數(shù)據(jù)時(shí)間為: '.$timer->spent(); unset($timer); //var_dump($result);

運(yùn)行結(jié)果:

普通mysql運(yùn)行1000條數(shù)據(jù)時(shí)間為: 0.011621秒

普通mysql運(yùn)行10000條數(shù)據(jù)時(shí)間為: 0.07766891秒

普通mysql運(yùn)行100000條數(shù)據(jù)時(shí)間為: 0.10834217秒

預(yù)查詢mysql運(yùn)行1000條數(shù)據(jù)時(shí)間為: 0.00963211秒

預(yù)查詢mysql運(yùn)行10000條數(shù)據(jù)時(shí)間為: 0.04614592秒

預(yù)查詢mysql運(yùn)行100000條數(shù)據(jù)時(shí)間為: 0.05989885秒

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

您可能感興趣的文章:

MySQL中預(yù)處理語(yǔ)句prepare、execute與deallocate的使用教程PHP5 mysqli的prepare準(zhǔn)備語(yǔ)句使用說明MySQL prepare語(yǔ)句的SQL語(yǔ)法MySQL prepare原理詳解
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 潍坊市| 大英县| 甘洛县| 朝阳区| 桐梓县| 枣庄市| 论坛| 洪湖市| 台北县| 芦溪县| 肃北| 肃南| 旺苍县| 临沂市| 高碑店市| 潜山县| 三穗县| 屏东市| 平凉市| 兴隆县| 隆回县| 吴桥县| 雷波县| 彭阳县| 樟树市| 简阳市| 石景山区| 哈密市| 大名县| 大安市| 平原县| 宾阳县| 湛江市| 乐陵市| 寻乌县| 嘉义县| 宿州市| 广宁县| 慈利县| 紫阳县| 常宁市|