0

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);
mysql_fetch_row($result);

it takes the regular 0.008 seconds or so.

As far as I know, the con of mysql_fetch_row 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 $r['col_name'] but would instead have to use something like $r[0][3]. Is that right?

What alternatives are there?

1
  • it's not mysql_fetch_array issue for sure. You have to investigate more Commented Feb 14, 2011 at 18:13

1 Answer 1

2

Try mysql_fetch_assoc($result);

Below note from: php.net

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.