mysql_fetch array() vs. mysql_fetch_row()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lordrt
Forum Commoner
Posts: 34
Joined: Sun Jul 19, 2009 11:44 pm

mysql_fetch array() vs. mysql_fetch_row()

Post by lordrt »

Hi again
Can anyone plz explain the difference between mysql_fetch_array() and mysql_fetch_row() using some code examples? I read on the php website but could not grasp it properly. :arrow:
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: mysql_fetch array() vs. mysql_fetch_row()

Post by jayshields »

http://uk3.php.net/mysql_fetch_array
The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: mysql_fetch array() vs. mysql_fetch_row()

Post by onion2k »

By default mysql_fetch_array returns two arrays merged into one, an associative array of field names, and a numeric array like mysql_fetch_row. That's the only difference. You should be using mysql_fetch_object* anyway though, so there's no reason to worry about any differences.

* When you eventually decide to use an abstraction library, which you will, you'll find they all access data like mysql_fetch_object, so it's best to learn that approach from the beginning.
lordrt
Forum Commoner
Posts: 34
Joined: Sun Jul 19, 2009 11:44 pm

Re: mysql_fetch array() vs. mysql_fetch_row()

Post by lordrt »

thanks onion2k will try the fetch_object
lordrt
Forum Commoner
Posts: 34
Joined: Sun Jul 19, 2009 11:44 pm

Re: mysql_fetch array() vs. mysql_fetch_row()

Post by lordrt »

jayshields wrote:http://uk3.php.net/mysql_fetch_array
The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
thanks jayshields
Post Reply