以下查询采取10.86secs发起,PHP加载倍
$sql="SELECT items.id i_id, status,manufacturerid,model,label,cpuno,corespercpu
from items,item2soft
where item2soft.itemid=items.id AND item2soft.softid={$r['id']}
order by label asc ";
尽管此代码取码23.73secs
$sql="SELECT items.id i_id, status,manufacturerid,model,label,cpuno,corespercpu
from items,item2soft
where item2soft.itemid=items.id AND item2soft.softid={$r['id']}";
唯一的区别两者是后者具有ORDER BY关键字。有什么办法让它更快。请随时问我任何东西。感谢您的帮助:)
做一个解释对数据库的查询,看看,看看什么(如果有的话)正在使用的索引 –
**通过构建带有外部变量的SQL语句,您可以全面开放SQL注入攻击。**另外,任何带有单引号的输入数据,如“O'Malley”的名称,都会导致您的SQL查询。请了解使用参数化查询(最好是使用PDO模块)来保护您的Web应用程序。 http://bobby-tables.com/php有例子让你开始,并且[这个问题](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in- php)有很多例子的细节。 –