- PHP Basics
- PHP Home
- PHP Environment Setup
- PHP Getting Started
- PHP Basic Syntax
- PHP echo
- PHP print
- PHP echo Vs print
- PHP Comments
- PHP Data Types
- PHP Variables
- PHP Variable Scope
- PHP gettype()
- PHP Constants
- PHP Operators
- PHP Program Control
- PHP Decision Making
- PHP if-elseif-else
- PHP switch
- PHP Loops
- PHP for Loop
- PHP while Loop
- PHP do-while Loop
- PHP foreach Loop
- PHP break & continue
- PHP Popular Topics
- PHP Arrays
- PHP print_r()
- PHP Strings
- PHP Functions
- PHP References
- PHP Object Oriented
- PHP Object Oriented
- PHP Classes & Objects
- PHP Member Variable
- PHP Member Function
- PHP Encapsulation
- PHP Data Abstraction
- PHP Inheritance
- PHP Constructor Destructor
- PHP Polymorphism
- PHP Web Developments
- PHP Web Developments
- PHP GET & POST
- PHP Read Requested Data
- PHP File Handling (I/O)
- PHP File Handling (I/O)
- PHP fopen() | Open File
- PHP Create a File
- PHP fwrite() | Write to File
- PHP fread() | Read File
- PHP feof()
- PHP fgetc()
- PHP fgets()
- PHP fclose() | Close File
- PHP unlink() | Delete File
- PHP Append to File
- PHP copy() | Copy File
- PHP file_get_contents()
- PHP file_put_contents()
- PHP file_exists()
- PHP filesize()
- PHP rename() | Rename File
- PHP fseek()
- PHP ftell()
- PHP rewind()
- PHP disk_free_space()
- PHP disk_total_space()
- PHP mkdir() | Create Directory
- PHP rmdir() | Remove Directory
- PHP glob() | Get Files/Directories
- PHP basename() | Get filename
- PHP dirname() | Get Path
- PHP filemtime()
- PHP file()
- PHP Advanced
- PHP Cookies
- PHP Sessions
- PHP Send Emails
- PHP Serialization
- PHP Namespaces
- PHP File Upload
- PHP Date and Time
- PHP Image Processing
- PHP Regular Expression
- PHP Predefined Variables
- PHP Error Handling
- PHP Debugging
- PHP and MySQLi Tutorial
- PHP and MySQLi Home
- PHP MySQLi Setup
- PHP MySQLi Create DB
- PHP MySQLi Create Table
- PHP MySQLi Connect to DB
- PHP MySQLi Insert Record
- PHP MySQLi Fetch Record
- PHP MySQLi Update Record
- PHP MySQLi Delete Record
- PHP MySQLi SignUp Page
- PHP MySQLi LogIn Page
- PHP MySQLi Store User Data
- PHP MySQLi Close Connection
- PHP connect_errno
- PHP connect_error
- PHP query()
- PHP fetch_row()
- PHP fetch_assoc()
- PHP fetch_array()
- PHP free_result()
- PHP error
- PHP prepare()
- PHP bind_param()
- PHP execute()
- PHP fetch()
- PHP store_result()
- PHP num_rows
- PHP bind_result()
- PHP get_result()
- PHP mysqli_result Class
- PHP Error Constants
- PHP mysqli_driver()
- PHP Misc
- PHP error_reporting()
- PHP Escape Special Characters
- PHP htmlspecialchars()
- PHP new
- PHP header()
- PHP getallheaders()
- PHP empty()
- PHP isset()
- PHP unset()
- PHP exit()
- PHP exit Vs break
- PHP include()
- PHP require()
- PHP include() Vs require()
- PHP AJAX & XML
- PHP AJAX
- PHP XML
- PHP File Handling Functions
- PHP abs()
- PHP Test
- PHP Online Test
- Give Online Test
- All Test List
PHP mysqli_result class
This article is created to list properties and methods of mysqli_result class, along with brief description and example.
PHP mysqli_result Class Properties and Description
Property | Description |
---|---|
current_field | Used to get the current field offset of 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 of current row in the result set |
num_rows | Used to get the number of rows |
PHP mysqli_result Class Methods and Description
Method | Description |
---|---|
__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 row as an associative array or as a numeric array or as both |
fetch_array() | Used to fetch the next row, as an associative array or as a numeric array or as 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 next row as an object |
fetch_row() | Used to fetch 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 mysqli_result class, let's see the table, that are going to use in the example:
PHP mysqli_result Class Properties Example
This examples uses the two famous and most 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 Methods Example
This examples uses some of the properties of 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 above example on 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 »
Like/Share Us on Facebook 😋