Difference between mysql_fetch_row(), mysql_fetch_array() and mysql_fetch_object() in php

 
The functions mysql_fetch_row(), mysql_fetch_array() and mysql_fetch_object() return one row from the result, and then move the pointer on. If there are no more rows to fetch, it returns false. This means you can you use a very simple while loop:
 
$result=mysql_query("SELECT * FROM sometable");
while($row=mysql_fetch_row($result)){
do_something_with_row();
}
 
This will automatically terminate when the last row has been processed.
 
mysql_fetch_row()
—————————-
It returns the results in a numeric array ($row[0], $row[1] etc).


 
mysql_fetch_array()
——————————
It returns a the results an array containing both numeric array ($row[0], $row[1] etc) and associative keys ($row["name"], $row["email"] etc).


 
mysql_fetch_object()
——————————–
It returns an object ($row->name, $row->email etc).


 
You can leave a response, or trackback from your own site.

Leave a Reply