Is there a performance difference between using mysql_result and mysql_array_assoc to loop through a large SQL select result?
2 Answers
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.
2 Comments
SELECT *, as that cuts down on resources that MySQL needs too.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()