Posted by Thurein on 1st December 2010

Difference between php mysql functions mysql_fetch_object(), mysql_fetch_assoc() and mysql_fetch_array()

Some of my friends are asked me. What’s difference between php functions mysql_fetch_object(), mysql_fetch_assoc() and mysql_fetch_array()? and how to use it ? If you also don’t known about it , please have a look example codes below. I think you would understand it.

mysql_fetch_object()

while ($each= mysql_fetch_object($result)) {
    echo $each->first_name;
    echo $each->last_name;
}

mysql_fetch_assoc()

while ($each= mysql_fetch_assoc($result)) {
    echo $each["first_name"];
    echo $each["last_name"];
}

mysql_fetch_array()

while ($each= mysql_fetch_array($result)) {
    echo $each[0];
    echo $each[1] ;
}
  • About Thurein Soe
    Visit Thurein's website.

    Freelance Web Developer. Founder of The Tech Space. Follow me on Twitter.

  • No comments yet!

    Post your comments