Jump to content

Difference between fetch_row() and fetch_object()


mcloan

Recommended Posts

[quote author=thorpe link=topic=113475.msg461148#msg461148 date=1162394898]
One fetches a row as an array, the other as an object.
[/quote]

Sorry, I am in the process of learning, can you provide an example of what the difference is between a row and object?

Thank you.
They both return a row. One however is returned as a numeric array of database fields, the other as an object with each field as a property. You can also retrieve an associative array which is a little easier to work with IMO.

eg;

[code=php:0]
// numeric array.
$row = mysql_fetch_row($result);
echo $row[0]; // prints the first field of the row.

// associative array.
$row = mysql_fetch_assoc($result);
echo $row['id']; // prints the filed called id.

// an object.
$obj = mysql_fetch_object($result);
echo $obj->id; // prints the field called id.
[/code]

If you dont know what an object is you probably don't need them just yet. You can read about them [url=http://php.net/oop]here[/url] though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.