So what is the deeper defference between these functions? I know how to use both of them and which arrays are produced each time. But, can anyone explain why use the first function instead of calling the second.
Thanks
So what is the deeper defference between these functions? I know how to use both of them and which arrays are produced each time. But, can anyone explain why use the first function instead of calling the second.
Thanks
I'd say use mysql_fetch_array as a standard just in case you want to make use of the associative-array features it generates, either now or later. PHP Net points out that the performance advantages of mysql_fetch_row are minimal and recommends using mysql_fetch_array every time. If you have a very large website with dozens of mysql queries in every page, you might get a slight performance advantage from using mysql_fetch_row, simply because the array contains less info.
If you want real performance advantages, avoid using SELECT * FROM ... and define which fields you actually want. See today's article by Marion Weerning on optimizing your website: http://www.phpbuilder.com/columns/weerning20021209.php3
My current knowledge doesn't stretch any further. Does this answer your question?
Norman
To be more precise:
[man]mysql_fetch_row[/man] returns row as indexed array (i.e. a value may be addressed as, say, $row[0]),
[man]mysql_fetch_assoc[/man] returns it as associative array (i.e. a value may be addressed as, say, $row['id']),
[man]mysql_fetch_array[/man] returns both (i.e. the same value may be addressed both as $row[0] and $row['id']).
So, mysql_fetch_array() consumes twice as much memory, as other two. Still, in case you don't store extremely large blobs in db, it doesn't make much difference.
Personally I use only mysql_fetch_assoc(), because it lets you work with column names rather than column numbers.
Why is this important? Because the column-number depends on the order in which you select the values in the query. For example, if you do: "SELECT firstname, lastname" the numbers are reversed compared to "SELECT lastname, firstname", but if you use the column-name, then firstname is allways firstname, and lastname is allways lastname.
This means you can select columns in any order you like (or any order the database likes) and you'll never have to change the rest of the script.
This also means you do'nt have to go though every single query when you insert a new column somewhere in the table, or when you re-build the entire database.
And finally, you get to use the column-name, so you always know exactly what you are talking about when you say $aRow['firstname']. (that's a lot clearer than ($aRow[1])