PHP mysqli_fetch_object() Function

PHP mysqli_fetch_object() function returns the current row of a result set as an object.

Syntax

object mysqli_fetch_object(result,class_name,params);

mysqli_fetch_object() Function Parameter

ParameterDescription
result :Required parameter. Mention a result set identifier returned by mysqli_query().
class_name :Optional parameter. The name of the class to instantiate, set the properties of and return. If not specified, a stdClass object is returned.
params :Optional parameter. An array of parameters to pass to the constructor for classname objects.

mysqli_fetch_object() Function Return Value

Return Values :Returns an object with string properties that correspond to the fetched row, or FALSE if there are no more rows.

mysqli_fetch_object() Function Example

<?php
$con = mysqli_fetch_objectt("localhost","user","password","db");

if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT fname, lname FROM employee";
$sql_result = mysqli_query($con, $sql);

while ($obj = mysqli_fetch_object($sql_result))
{
 echo $obj->FirstName . " " . $obj->LastName;
}

mysql_free_result($sql_result);

mysqli_close($con);
?>