Forum Moderators: coopster
I understand they both pull 'arrays' -- another term for lists -- from a database. But I am confused as to which list they are talking about.
If you look at the commands themselves, it seems fetching an array is fetching the entire database as a list and fetching a row is just fetching the next row with the dataset in each column as the list.
So, if you have a database with
ID......ColumnA.....ColumnB
-------------------------------------
1........dataA............dataB
2........dataC...........dataD
It seems like Fetch_row' should just get you a list like this:
1,dataA,dataB
and 'Fetch_array' get you a list like this:
1,dataA, dataB
2,dataC, dataD
But I don't think that is the case. Can someone clarify this?
mysql_fetch_array() is an extended version of mysql_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.An important thing to note is that using mysql_fetch_array() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.
The optional second argument result_type in mysql_fetch_array() is a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH ..... MYSQL_BOTH is the default for this argument
mysql_fetch_assoc() and mysql_fetch_row() each have a specific function, select as associative array or with numeric indices.
mysql_fetch_array gives you the most flexibilty, you can also force it to act like either of the above by specifying the result_type in the function call.
It falls more into the how you do things category I think. fetch_array is the most versatile but you could do any of them and acheive the same result.
<added>all three functions when called once will return one row of data.
Or is there a specific instance when one is clearly better than the other?