mysql_fetch_assoc vs. mysql_fetch_array
Moderator: General Moderators
mysql_fetch_assoc vs. mysql_fetch_array
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?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: mysql_fetch_assoc vs. mysql_fetch_array
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.
(#10850)
Re: mysql_fetch_assoc vs. mysql_fetch_array
So using either one really makes no difference.
Re: mysql_fetch_assoc vs. mysql_fetch_array
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: mysql_fetch_assoc vs. mysql_fetch_array
I'll be damned if anyone used speed as an argument in using on over another 
Re: mysql_fetch_assoc vs. mysql_fetch_array
I sure as hell wouldnt LOL
Re: mysql_fetch_assoc vs. mysql_fetch_array
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 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 otherJohn Cartwright wrote:I'll be damned if anyone used speed as an argument in using on over another
Re: mysql_fetch_assoc vs. mysql_fetch_array
Old Thread = Locked
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: mysql_fetch_assoc vs. mysql_fetch_array
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.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 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 otherJohn Cartwright wrote:I'll be damned if anyone used speed as an argument in using on over another
EDIT | Double sorry, didn't realize it was locked!