Page 1 of 1

mysql_fetch array() vs. mysql_fetch_row()

Posted: Mon Aug 03, 2009 5:06 am
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:

Re: mysql_fetch array() vs. mysql_fetch_row()

Posted: Mon Aug 03, 2009 5:30 am
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).

Re: mysql_fetch array() vs. mysql_fetch_row()

Posted: Mon Aug 03, 2009 5:33 am
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.

Re: mysql_fetch array() vs. mysql_fetch_row()

Posted: Mon Aug 03, 2009 5:51 am
by lordrt
thanks onion2k will try the fetch_object

Re: mysql_fetch array() vs. mysql_fetch_row()

Posted: Mon Aug 03, 2009 5:52 am
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