PHP mysqli_result class

This article is created to list the properties and functions of the "mysqli_result" class, along with a brief description and example.

The "mysqli_result" class is essential when working with PHP and MySQL databases because it allows developers to interact with the result sets returned from database queries. This class extends the "mysqli" class and provides a set of properties and functions for manipulating and retrieving data from the result set.

PHP mysqli_result class properties and description

The following is a list of "mysqli_result" class properties and their descriptions.

PHP mysqli_result Class Methods and Description

Following is a list of "mysqli_result" class functions along with their brief descriptions.

PHP mysqli_result class example

Before creating an example of the mysqli_result class, let's see the table that we are going to use in the example:

php mysqli result class example table

PHP mysqli_result class properties example

This example uses the two most famous and commonly used properties of the mysqli_result class in PHP:

<?php
   $conn = new mysqli("localhost", "root", "", "codescracker");
   
   if(!$conn->connect_errno)
   {
      $stmt = $conn->prepare("SELECT * FROM customer");
      $stmt->execute();
      $result = $stmt->get_result();
      
      echo "<h2>Using field_count Property</h2>";
      echo $result->field_count;
      echo "<HR>";
      
      echo "<h2>Using num_rows Property</h2>";
      echo $result->num_rows;
      echo "<HR>";
   }
   $conn->close();
?>

The output is:

php mysqli result class properties

PHP mysqli_result class functions example

This example uses some of the properties of the PHP mysqli_result class:

<?php
   $conn = new mysqli("localhost", "root", "", "codescracker");
   
   if(!$conn->connect_errno)
   {
      $stmt = $conn->prepare("SELECT * FROM customer");
      $stmt->execute();
      $result = $stmt->get_result();
      
      echo "<h2>Using fetch_all() Method</h2>";
      print_r($result->fetch_all());
      echo "<HR>";
      
      echo "<h2>Using fetch_field() Method</h2>";
      print_r($result->fetch_field());
      echo "<HR>";
      
      echo "<h2>Using fetch_fields() Method</h2>";
      print_r($result->fetch_fields());
      echo "<HR>";
   }
   $conn->close();
?>

The output of the above example on the mysqli_result class, based on my current customer table, should be:

Using fetch_all() Method
Array ( [0] => Array ( [0] => 1 [1] => Olivia [2] => 28 [3] => codescracker.com@gmail.com ) [1] => Array ( [0] => 2 [1] => Charlotte [2] => 24 [3] => charloette@xyz.com ) [2] => Array ( [0] => 4 [1] => Sophia [2] => 29 [3] => sophia@xyz.com ) [3] => Array ( [0] => 5 [1] => Benjamin [2] => 31 [3] => benjamin@xyz.com ) [4] => Array ( [0] => 6 [1] => Susan [2] => 35 [3] => susan@xyz.com ) [5] => Array ( [0] => 7 [1] => Martin [2] => 35 [3] => martin@xyz.com ) )

Using fetch_field() Method stdClass Object ( [name] => id [orgname] => id [table] => customer [orgtable] => customer [def] => [db] => codescracker [catalog] => def [max_length] => 0 [length] => 6 [charsetnr] => 63 [flags] => 49699 [type] => 3 [decimals] => 0 )
Using fetch_fields() Method Array ( [0] => stdClass Object ( [name] => id [orgname] => id [table] => customer [orgtable] => customer [def] => [db] => codescracker [catalog] => def [max_length] => 0 [length] => 6 [charsetnr] => 63 [flags] => 49699 [type] => 3 [decimals] => 0 ) [1] => stdClass Object ( [name] => name [orgname] => name [table] => customer [orgtable] => customer [def] => [db] => codescracker [catalog] => def [max_length] => 0 [length] => 120 [charsetnr] => 45 [flags] => 4097 [type] => 253 [decimals] => 0 ) [2] => stdClass Object ( [name] => age [orgname] => age [table] => customer [orgtable] => customer [def] => [db] => codescracker [catalog] => def [max_length] => 0 [length] => 2 [charsetnr] => 63 [flags] => 32768 [type] => 3 [decimals] => 0 ) [3] => stdClass Object ( [name] => email [orgname] => email [table] => customer [orgtable] => customer [def] => [db] => codescracker [catalog] => def [max_length] => 0 [length] => 160 [charsetnr] => 45 [flags] => 4097 [type] => 253 [decimals] => 0 ) )

PHP Online Test


« Previous Tutorial Next Tutorial »


Liked this post? Share it!