3

Is there a performance difference between using mysql_result and mysql_array_assoc to loop through a large SQL select result?

2 Answers 2

3

From the mysql_result() manual page:

When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.

So it seems that mysql_array_assoc(), one of the functions that quote refers to, is going to be your best bet.

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

2 Comments

Any idea as to how long the result needs to be before the performance difference is notable?
Nope, you'd have to do some benchmarking. But if you're looping through multiple records, I would just use mysql_array_assoc() and check the fields on the code side, rather than trying to pick out individual cells. If you only need certain columns, make sure you're selecting only those and not doing SELECT *, as that cuts down on resources that MySQL needs too.
0

Yes (fetching an entire row is faster than mysql_result), and it's mentioned clearly in the mysql_result documentation:

When working on large result sets, you should consider using one of the functions that fetch an entire row (mysql_fetch_*). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result()

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.