English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and examples of PHP mysqli_stmt_store_result() function

PHP MySQLi Reference Manual

The mysqli_stmt_store_result() function stores the result set from the prepared statement.

Definition and usage

The mysqli_stmt_store_result() function accepts a statement object as a parameter and stores the result set of the given statement locally when executing SELECT, SHOW, or DESCRIBE statements.

Syntax

mysqli_stmt_store_result($stmt);

Parameter

Serial numberParameters and descriptions
1

stmt(essential)

This is the object representing the prepared statement.

2

offset(essential)

This is the integer value representing the required row (must be between 0 and the total number of rows in the result set).

Return value

The PHP mysqli_stmt_attr_get() function returns a boolean value, and returns if successfulTRUE; if failed, then returnFALSE.

PHP version

This function was initially in PHP version5This is introduced and can be used in all higher versions.

Online example

The following examples demonstratemysqli_stmt_store_result()Usage of the function (procedural style)-

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   mysqli_query($con, "CREATE TABLE Test(Name VARCHAR(255), AGE INT)");
   mysqli_query($con, "insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27");
   print("Create table.....\n");
   //Read record
   $stmt = mysqli_prepare($con, "SELECT * FROM Test");
   //Execute statement
   mysqli_stmt_execute($stmt);
   //Store result
   mysqli_stmt_store_result($stmt);
   //Number of rows
   $count = mysqli_stmt_num_rows($stmt);
   print("Number of rows in the table: "=>$count."\n");
   //End statement
   mysqli_stmt_close($stmt);
   //Close connection
   mysqli_close($con);
?>

Output result

Create table.....
Number of rows in the table: 3

Online example

In the object-oriented style, the syntax of this function is$stmt-> store_result();.The following is an example of this function in an object-oriented style;

<?php
   //Establish connection
   $con = new mysqli("localhost", "root", "password", "mydb");
   $con -> query("CREATE TABLE Test(Name VARCHAR(255), AGE INT)");
   $con -> query("insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27");
   print("Create table.....\n");
   $stmt = $con -> prepare("SELECT * FROM Test");
   //Execute statement
   $stmt->execute();
   //Store result
   $stmt->store_result();
   print("Line number".$stmt ->num_rows);
   //End statement
   $stmt->close();
   //Close connection
   $con->close();
?>

Output result

Create table.....
Line number: 3

PHP MySQLi Reference Manual