0
我的問題是,我的網頁加載速度很慢....(2-3秒) 我測試了問題的來源,我看到的是該部分:$ query = mysql_query .... ..緩慢的mysql數據加載
這裏是頁:
require_once('config/db_config.php');
require_once 'class/PHPTemplate.class.php';
session_start();
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
$query = mysql_query("SELECT * FROM pages WHERE url_address='Skarabeol'");
$numrows = mysql_num_rows($query);
if($numrows!=0) {
while ($row = mysql_fetch_assoc($query)) {
$content=$row['content'];
$title=$row['title'];
}
} else {Echo "Page not found!";}
$rows = array(
array(1.1, 1.2, 1.3),
array(2.1, 2.2, 2.3),
array(3.1, 3.2, 3.3),
array(4.1, 4.2, 4.3)
);
$tpl = new PHPTemplate();
$tpl->add('title', $title);
$tpl->add('content', $content);
$tpl->add('current_year', date('Y'));
//$tpl->add('rows', $rows);
//$tpl->add('rows_count', count($rows));
$tpl->load('footer', 'tpl/footer.tpl');
$tpl->display('tpl/page.tpl');
?>
而且它會加載一個模板文件(我沒有測試MySQL連接,它工作得很好)。
這裏是你想看到它的情況下配置文件...
define('DB_HOST', 'localhost');
define('DB_USER', 'xxxxxxx');
define('DB_PASSWORD', 'xxxxxxxxxx');
define('DB_DATABASE', 'xxxxxxxxx');
什麼,我做錯了什麼?
請讓我知道,如果你需要我給你看別的東西....提前致謝!
你有對'url_address'的指數? – AlexP 2013-05-02 10:14:03
另外,'SELECT *'會比列出所有列名要慢 – AlexP 2013-05-02 10:14:48
頁表中有多少數據?這個數據庫服務器位於哪裏? – MatthewMcGovern 2013-05-02 10:16:30