国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 江口县| 新乐市| 嵊州市| 梧州市| 乌鲁木齐县| 石屏县| 益阳市| 通榆县| 龙泉市| 嘉鱼县| 共和县| 邢台县| 汕头市| 衡山县| 潮州市| 巴林右旗| 马山县| 阿尔山市| 禹城市| 高阳县| 红桥区| 会同县| 介休市| 南江县| 中卫市| 宁明县| 武乡县| 清流县| 岚皋县| 平南县| 南皮县| 江安县| 托里县| 鲜城| 晴隆县| 安达市| 永城市| 六枝特区| 淅川县| 额尔古纳市| 宣威市|