我有一个查询,它在 2 秒内在 Workbench 中执行。当我在 PHP 文件中执行它大约需要 40 秒!任何想法为什么?
谢谢。询问:
SELECT
sum((1 - (Data.Data1.`Ggdata` / 100)) * (Data.Data1.`Datagg`)) As 'EUH'
FROM
Data.Data1
INNER JOIN
(Data.trans_UN, Data.input_Ex, Data.trans_M, Data.trans_Pa) ON (Data.trans_Une.Une_ID = Data.input_Data1.Une_ID
AND Data.trans_Une.GN = Data.input_Ex.GN
AND Data.input_Ex.EQ = Data.trans_M.EQ
AND Data.input_Ex.GL = Data.trans_M.GL
AND Data.input_Ex.MN = Data.trans_P.GP)
WHERE
Data.tGModel = 'Model1'
GROUP BY Data.Data1.`Year` , Data.Data1.`Month`
PHP代码:
$time_mysql_data = -microtime(true);
$sth1 = mysql_query("
SELECT
sum((1 - (Data.Data1.`Ggdata` / 100)) * (Data.Data1.`Datagg`)) As 'EUH'
FROM
Data.Data1
INNER JOIN
(Data.trans_UN, Data.input_Ex, Data.trans_M, Data.trans_Pa) ON (Data.trans_Une.Une_ID = Data.input_Data1.Une_ID
AND Data.trans_Une.GN = Data.input_Ex.GN
AND Data.input_Ex.EQ = Data.trans_M.EQ
AND Data.input_Ex.GL = Data.trans_M.GL
AND Data.input_Ex.MN = Data.trans_P.GP)
WHERE
Data.tGModel = 'Model1'
GROUP BY Data.Data1.`Year` , Data.Data1.`Month`");
$time_mysql_data += microtime(true);
$time_php_data = -microtime(true);
$rows1 = array();
$rows1['name'] = 'EUH';
while($r = mysql_fetch_array($sth1)) {
$rows1['data'][] = $r['EUH'];
};
$time_php_data += microtime(true);
我知道我应该使用 mysqli 或 PDO,我正在这样做。这段代码还没有更新:)
谢谢