SQL滞后问题

时间:2017-11-08 20:51:34

标签: php sql pdo

好的,当我运行这个sql和一堆PHP编码似乎需要一段时间来加载。我通过数据库sql部分运行sql,加载大约需要5到6秒。如果我添加其他任何东西,我得到网关超时因为它是长的。想知道是否有更简单的方法使这个加载更快或缩短sql代码?

} elseif ($_GET['page'] == "newwartab") {
$servername = $config['sqlserver'];
$dbname = $config['sqldb'];
$conn = new PDO("mysql:host=$servername;dbname=$dbname",     $config['sqluser'], $config['sqlpass']);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//error_reporting(E_ALL);
//error_reporting(E_ALL);

$condition="`stats`.`name`=`chains`.`name` AND `chains`.`tag` IN ('Age Approved', 'SR-AaA', 'Sweet Revenge', 'SR-AaA-LH', 'SR-AaA-LH Slayer Squad', 'Against All Authority', 'Black Sails', 'DEMK', 'Loser')";
if ($login==0) { die(); }
$query = $conn->prepare("SELECT `stats`.`spy` from `stats` WHERE `stats`.`name`='$user' LIMIT 1");
$query->execute();
$spy = $query->fetch(PDO::FETCH_ASSOC);
//$spy = mysql_fetch_array($query);
$spy = $spy['spy'];
$condition=$condition." AND `stats`.`sentry` <= ".$spy*2.2;
?>

$query = $conn->prepare("SELECT `stats`.`name`, `stats`.`active`, `stats`.`id`, `stats`.`sentry`, `stats`.`spy`, `stats`.`rank`, `stats`.`maxed`, `chains`.`name`, `chains`.`tag`, ((`stats`.`bpm`*1000000)+(`stats`.`ch`*450000)+(`stats`.`is`*1000000)+(`stats`.`ds`*200000)+(`stats`.`nun`*1000000)+(`stats`.`lt`*1000000)+(`stats`.`key`*600000)+(`stats`.`dog`*250000)) AS `tvalue` FROM `stats`, `chains` WHERE ".$condition." ORDER BY `tvalue` DESC LIMIT :start_from, :items_per_page");
$query->bindParam(':start_from', $start_from);
$query->bindParam(':items_per_page', $items_per_page);
while ($results = $query->fetch(PDO::FETCH_ASSOC)){//end here and the rest is just echo's}

我遗漏了php的原因我不认为它的问题导致它没有sql加载正常。

0 个答案:

没有答案