PHP - Function MySQLi Fetch Object



Syntax

mysqli_fetch_object(result,classname,params);

Definition and Usage

It returns the current row of a result set, as an object.

Return Values

It returns string properties for the fetched row or NULL if there are no more rows in the result set

Parameters

Sr.No Parameters & Description
1

result

It specifies the result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result()

2

classname

It specifies the name of the class to instantiate

3

params

It specifies an array of parameters to pass to the constructor for classname objects

Example

Try out the following example

<?php
   $connection_mysql = mysqli_connect("localhost","user","password","db");
   
   if (mysqli_connect_errno($connection_mysql)){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   
   $sql = "SELECT name FROM emp";
   
   if ($result = mysqli_query($connection_mysql,$sql)){
      while ($obj = mysqli_fetch_object($result)){
         print $obj->name;
         print "\n";
      }
      mysqli_free_result($result);
   }
   mysqli_close($connection_mysql);
?>
php_function_reference.htm
Advertisements