English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_stmt_store_result() function stores the result set from the prepared statement.
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.
mysqli_stmt_store_result($stmt);
Serial number | Parameters 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). |
The PHP mysqli_stmt_attr_get() function returns a boolean value, and returns if successfulTRUE; if failed, then returnFALSE.
This function was initially in PHP version5This is introduced and can be used in all higher versions.
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
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