Page 1 of 1

mysql_fetch_assoc vs. mysql_fetch_array

Posted: Fri May 30, 2008 11:56 am
by icesolid
I always use mysql_fetch_array($result) when running a query. I was just wondering is there any advantage (ex: speed) using mysql_fetch_assoc instead?

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Fri May 30, 2008 12:53 pm
by Christopher
I doubt that there is any speed difference. The time is taken with the fetch, not PHP putting it into an array of one type or another.

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Fri May 30, 2008 1:17 pm
by icesolid
So using either one really makes no difference.

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Fri May 30, 2008 2:34 pm
by Luke
Probably not any noticeable difference... although mysql_fetch_array MUST be at least somewhat slower because it does all of the work that mysql_fetch_assoc does PLUS a numeric array.

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Fri May 30, 2008 2:49 pm
by John Cartwright
I'll be damned if anyone used speed as an argument in using on over another :twisted:

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Fri May 30, 2008 3:30 pm
by Luke
I sure as hell wouldnt LOL

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Thu May 21, 2009 5:20 pm
by devhen
mysql_fetch_assoc would be faster than mysql_fetch_array because mysql_fetch_array is populating numeric *and* associative arrays for each result. mysql_fetch_array($result, MYSQL_ASSOC) is equivalent to mysql_fetch_assoc. Furthermore, mysql_fetch_array($result, MYSQL_NUM) is the fastest because it is only populating a numeric array for each result. This makes it faster and uses less bandwidth.
John Cartwright wrote:I'll be damned if anyone used speed as an argument in using on over another :twisted:
John Cartwright has obviously never seen a result set larger than 10 million rows, let alone 1 billion, and he'll have to be damned because there is definitely a speed difference on very large result sets and I am using speed as an argument for using one over the other ;)

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Thu May 21, 2009 5:23 pm
by Benjamin
Old Thread = Locked

Re: mysql_fetch_assoc vs. mysql_fetch_array

Posted: Mon Aug 17, 2009 7:17 pm
by John Cartwright
devhen wrote:mysql_fetch_assoc would be faster than mysql_fetch_array because mysql_fetch_array is populating numeric *and* associative arrays for each result. mysql_fetch_array($result, MYSQL_ASSOC) is equivalent to mysql_fetch_assoc. Furthermore, mysql_fetch_array($result, MYSQL_NUM) is the fastest because it is only populating a numeric array for each result. This makes it faster and uses less bandwidth.
John Cartwright wrote:I'll be damned if anyone used speed as an argument in using on over another :twisted:
John Cartwright has obviously never seen a result set larger than 10 million rows, let alone 1 billion, and he'll have to be damned because there is definitely a speed difference on very large result sets and I am using speed as an argument for using one over the other ;)
Sorry to reply to this old topic. However, you would be mistaken in making that assumption. Reguardless, you have to be absolutely mad to be iterating a result set of 10 million rows. :banghead:

EDIT | Double sorry, didn't realize it was locked!