PHP mysql_fetch_object() function
Definition and usage
The mysql_fetch_object() function retrieves a row from the result set (record set) as an object.
If successful, this function from mysql_query() Get a line and return an object. If it fails or there are no more lines, return false.
Syntax
mysql_fetch_object(data)
Parameters | Description |
---|---|
data | Required. The data pointer to use. This data pointer is from mysql_query() The returned results. |
Tips and Notes
Note:Each subsequent call to mysql_fetch_object() returns the next row in the record set.
Note:mysql_fetch_object() with mysql_fetch_array() Similar, only one difference - it returns an object instead of an array. Indirectly, it also means that you can only access the array through field names, not offsets.
Example
<?php $con = mysql_connect("localhost", "peter", "abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("test_db",$con); $sql = "SELECT * from Person"; $result = mysql_query($sql,$con); while ($row = mysql_fetch_object($result)) { echo $row->FirstName . "<br />"; } mysql_close($con); ?>
Output:
John George Thomas