Why we need a function like fetch_object and what is the purpose of using it?

We have fetch_array to fetch a row from a result set... in what way the fetch_object function is useful... at which situation it is used? every question is like what is the difference and the answers is just like the following 'fetch_array" gives an array of any type but fetch_object will return an object.... but WHY???

Questions by jachmullan

Showing Answers 1 - 13 of 13 Answers

Fetch array normally retrives the records based on array index. i.e. like $row[1], but if you want to retrieve the record based on the column name we can use fetch_object i.e. $row['username']

mohit_php

  • Sep 17th, 2008
 

just read this script and you will be get cleared
<?php
mysql_connect
("hostname""user""password");
mysql_select_db("mydb");
$result mysql_query("select * from mytable");
while (
$row mysql_fetch_object($result)) {
    echo 
$row->user_id;
    echo 
$row->fullname;
}
mysql_free_result($result);
?>

amitverma

  • Feb 9th, 2009
 

Procedural programmers do use functional and OOPs programmers use class and objects.

So it's just a facility and not a burden on anybody. If you're following OOPs pattern then you may use mysql_fetch_object function, otherwise get the processing done using mysql_fetch_assoc function.

It all depends, the kind of model we're using. The only difference is whether you want to use array or object??

abc

  • Sep 12th, 2011
 

Fetch array normally retrieves the records based on array index. i.e. like $row[1], but if you want to retrieve the record based on the column name we can use fetch_object i.e. $row['username']

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions