mysql_fetch_array($ result,MYSQL_ASSOC)真的很慢

时间:2011-02-14 18:07:23

标签: php mysql

这是我的MySQL查询:

SELECT item_to_list_tb . * , item_tb . * , list_tb . * 
FROM item_to_list_tb, item_tb, list_tb
WHERE item_to_list_tb.list_id =3
AND item_to_list_tb.item_id = item_tb.item_id
GROUP BY item_to_list_tb.item_id
ORDER BY item_to_list_tb.item_ord
LIMIT 0 , 30

直接在MySQL数据库上需要0.008秒。

但是,当我在PHP中获得结果时,如果我使用

$result = mysql_query($sql, $this->svr_msconnect);
mysql_fetch_array($result, MYSQL_ASSOC));

4秒加载!

然而,当我使用

$result = mysql_query($sql, $this->svr_msconnect);
mysql_fetch_row($result);

需要常规的0.008秒左右。

据我所知,mysql_fetch_row的con是它没有给出列的名称。是对的吗?这意味着我无法回复$r['col_name']之类的内容,而是必须使用类似$r[0][3]的内容。是吗?

有哪些替代方案?

1 个答案:

答案 0 :(得分:2)

尝试mysql_fetch_assoc($result);

以下注释:php.net

注意:效果 需要注意的一点是,使用 mysql_fetch_assoc() 并不比使用mysql_fetch_row()慢得多 ,同时它提供了一个重要的附加值。

相关问题