English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_stmt_free_result() function releases the stored result memory of the given statement handle.
mysqli_stmt_free_result();The function accepts a (prepared) statement object as a parameter and releases the memory stored for the given statement result (when storing the result using the mysqli_stmt_store_result() function).
mysqli_stmt_free_result($stmt);
Serial number | Parameters and descriptions |
---|---|
1 | con(Necessary) This is the object representing the prepared statement. |
The PHP mysqli_stmt_free_result() function does not return any value.
This function was originally introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstrate:mysqli_stmt_free_result();Function usage (procedural style), returns the number of rows after releasing the result:
<?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); //Rows $count = mysqli_stmt_num_rows($stmt); print("Number of rows in the table: ":$count."\n"); //Freeing the resultset mysqli_stmt_free_result($stmt); $count = mysqli_stmt_num_rows($stmt); print("Number of rows after releasing the result: ":$count."\n"); //End statement mysqli_stmt_close($stmt); //Close connection mysqli_close($con); ?>
Output result
Create table..... Number of rows in the table: 3 Number of rows after releasing the result: 0
In the object-oriented style, the syntax of this function is$stmt->free_result();.Here 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("Number of rows stored:":$stmt ->num_rows); //Release memory of result set $stmt->free_result(); //End statement $stmt->close(); //Close connection $con->close(); ?>
Output result
Create table..... Number of rows stored: 3