数据库 
首页 > 数据库 > 浏览文章

php+mysql prepare 与普通查询的性能对比实例讲解

(编辑:jimmy 日期: 2024/10/19 浏览:3 次 )

php+mysql prepare 与普通查询的性能对比

实例代码如下:

<"select username,email from uc_members where uid < 100000"); 
$result = array(); 
http://www.manongjc.com/article/1194.html
while($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>预查询mysql运行100000条数据时间为: '.$timer->spent();  
unset($timer);  
//var_dump($result); 

运行结果:

普通mysql运行1000条数据时间为: 0.011621秒

普通mysql运行10000条数据时间为: 0.07766891秒

普通mysql运行100000条数据时间为: 0.10834217秒

预查询mysql运行1000条数据时间为: 0.00963211秒

预查询mysql运行10000条数据时间为: 0.04614592秒

预查询mysql运行100000条数据时间为: 0.05989885秒

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:Mysql更改默认引擎为Innodb的步骤方法
下一篇:Centos7下使用yum安装mysql数据库的详细教程(增强版)
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap