Francesco Francesco - 1 year ago 47
MySQL Question

mysql_fetch_array($result, MYSQL_ASSOC) is really slow

This is my MySQL query:

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

It takes 0.008 seconds when on a MySQL database directly.

However, when I get the results in PHP, if I use

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

it takes 4 seconds to load!

Whereas, when I use

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

it takes the regular 0.008 seconds or so.

As far as I know, the con of
is that it doesn’t give the name of the columns. Is that right? That would mean that I would not be able to echo something like
but would instead have to use something like
. Is that right?

What alternatives are there?


Try mysql_fetch_assoc($result);

Below note from:

Note: Performance An important thing to note is that using mysql_fetch_assoc() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.