- PHP Basics
- Learn PHP
- PHP Comments
- PHP Data Types
- PHP Variables
- PHP Operators
- PHP echo
- PHP print
- PHP echo vs. print
- PHP if else
- PHP switch
- PHP for Loop
- PHP while Loop
- PHP do...while Loop
- PHP foreach Loop
- PHP break and continue
- PHP exit()
- PHP exit() vs. break
- PHP isset()
- PHP Arrays
- PHP print_r()
- PHP unset()
- PHP Strings
- PHP Functions
- PHP File Handling
- PHP File Handling
- PHP Open File
- PHP Create a File
- PHP Write to File
- PHP Read File
- PHP feof()
- PHP fgetc()
- PHP fgets()
- PHP Close File
- PHP Delete File
- PHP Append to File
- PHP Copy File
- PHP file_get_contents()
- PHP file_put_contents()
- PHP file_exists()
- PHP filesize()
- PHP Rename File
- PHP fseek()
- PHP ftell()
- PHP rewind()
- PHP disk_free_space()
- PHP disk_total_space()
- PHP Create Directory
- PHP Remove Directory
- PHP Get Files/Directories
- PHP Get filename
- PHP Get Path
- PHP filemtime()
- PHP file()
- PHP include()
- PHP require()
- PHP include() vs. require()
- PHP mysqli Tutorial
- PHP mysqli Tutorial
- PHP and MySQL Setup
- PHP mysqli: Create Database
- PHP mysqli: Create Table
- PHP mysqli: Insert Record
- PHP mysqli: Update Record
- PHP mysqli: Fetch Record
- PHP mysqli: Delete Record
- PHP mysqli: SignUp Page
- PHP mysqli: LogIn Page
- PHP mysqli: Store User Data
- PHP mysqli Functions
- PHP mysqli_connect()
- PHP mysqli_close()
- PHP mysqli_connect_errno()
- PHP mysqli_connect_error()
- PHP mysqli_query()
- PHP mysqli_fetch_row()
- PHP mysqli_fetch_assoc()
- PHP mysqli_fetch_array()
- PHP mysqli_free_result()
- PHP mysqli_error()
- PHP mysqli_prepare()
- PHP mysqli_stmt_bind_param()
- PHP mysqli_stmt_execute()
- PHP mysqli_stmt_fetch()
- PHP mysqli_stmt_store_result()
- PHP mysqli_stmt_num_rows()
- PHP mysqli_stmt_bind_result()
- PHP mysqli_stmt_get_result()
- PHP mysqli_result class
- PHP mysqli_report()
- PHP error_reporting()
- PHP mysqli_real_escape_string()
- PHP htmlspecialchars()
- PHP Misc Topics
- PHP Object Oriented
- PHP new Keyword
- PHP header()
- PHP getallheaders()
- PHP Cookies
- PHP Sessions
- PHP Date and Time
- PHP GET vs. POST
- PHP File Upload
- PHP Image Processing
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.
- current_field: Used to get the current field offset of the result pointer.
- field_count: Used to get the number of fields (columns) available in the result set.
- lengths: Used to get the lengths of columns in the current row in the result set.
- num_rows: Used to get the number of rows.
PHP mysqli_result Class Methods and Description
Following is a list of "mysqli_result" class functions along with their brief descriptions.
- __construct(): Used to construct a mysqli_result object.
- data_seek(): Used to move the result pointer to an arbitrary row in the result set.
- fetch_all(): Used to fetch all result rows as an associative array, a numeric array, or both.
- fetch_array(): Used to fetch the next row as an associative array, a numeric array, or both.
- fetch_assoc(): Used to fetch the next row as an associative array.
- fetch_column(): Used to fetch a single column from the next row.
- fetch_field_direct(): Used to fetch metadata (data about data) for a single field (column).
- fetch_field(): Used to get the next field (column).
- fetch_fields(): Used to get an array of objects representing the fields.
- fetch_object(): Used to fetch the next row as an object.
- fetch_row(): Used to fetch the next row as an enumerated array.
- field_seek(): Used to set the result pointer to a specified field offset.
- free(): Used to free the memory that is associated with the result set.
- getIterator(): Used to retrieve an external iterator.
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 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 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 ) )
« Previous Tutorial Next Tutorial »