我有10萬條記錄 我到處打電話200次從數據庫或公共變量大數據選擇
功能getNameProcessPHP代碼與選擇從數據庫
function getNameProcess($id)
{
$time1=microtime(true);
$baseClass = new MsDatabase();
$query = "select CON_VALUE,CON_ID,CON_CATEGORY from content where CON_ID=$id and CON_VALUE<>'' and CON_CATEGORY='PRO_TITLE'";
$res= $baseClass->query($query,WF_WORKFLOW_DB_NAME);
$time2=microtime(true);
$timeTotal=($time2-$time1);
echo $timeTotal;
return $res[0]["CON_VALUE"];
}
PHP代碼與選擇從市民的餐桌內容可變
$contentTable=array();
function getNameProcess($id)
{
$time1=microtime(true);
$baseClass = new MsDatabase();
if(empty($GLOBALS['contentTable']))
{
$query = "select CON_VALUE,CON_ID,CON_CATEGORY from content ";
$GLOBALS['contentTable']= $baseClass->query($query,WF_WORKFLOW_DB_NAME_MARKAZE);
}
foreach($GLOBALS['contentTable'] as $R)
{
if($R['CON_ID']==$id && $R['CON_VALUE']!='' && $R['CON_CATEGORY']=='PRO_TITLE')
{
$time2=microtime(true);
$timeTotal=($time2-$time1);
echo $timeTotal;
return $R["CON_VALUE"];
}
}
return 0;
}
當使用數據庫獲取進程名$totalTime
爲1.2二,在使用時酒館lic變量totalTime是3.5秒?
爲什麼我用公用變量$totalTime
比使用數據庫時大?
如何減少$totalTime
?
感謝
的第一個查詢只在表中選擇一個行,第二個選擇所有行。將所有行從數據庫複製到PHP需要更長的時間。 – Barmar