Fonction PHP mysqli_stmt_free_result ()

Définition et utilisation

le mysqli_stmt_free_result() La fonction accepte un objet instruction (préparé) comme paramètre et libère la mémoire dans laquelle le résultat de l'instruction donnée est stocké (lorsque vous stockez le résultat en utilisant la fonction mysqli_stmt_store_result ()).

Syntaxe

mysqli_stmt_free_result($stmt);

Paramètres

Sr. Non Paramètre et description
1

con(Mandatory)

Il s'agit d'un objet représentant une instruction préparée.

Valeurs de retour

La fonction PHP mysqli_stmt_free_result () ne renvoie aucune valeur.

Version PHP

Cette fonction a été introduite pour la première fois dans la version 5 de PHP et fonctionne dans toutes les versions ultérieures.

Exemple

L'exemple suivant montre l'utilisation de la fonction mysqli_stmt_free_result () (dans le style procédural) -

<?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("Table Created.....\n");

   //Reading records
   $stmt = mysqli_prepare($con, "SELECT * FROM Test");

   //Executing the statement
   mysqli_stmt_execute($stmt);

   //Storing the result
   mysqli_stmt_store_result($stmt);

   //Number of 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 freeing the result: ".$count."\n");

   //Closing the statement
   mysqli_stmt_close($stmt);

   //Closing the connection
   mysqli_close($con);
?>

Cela produira le résultat suivant -

Table Created.....
Number of rows in the table: 3
Number of rows after freeing the result: 0

Exemple

Dans le style orienté objet, la syntaxe de cette fonction est $ stmt-> free_result (); Voici l'exemple de cette fonction dans le style orienté objet $ minus;

<?php
   //Creating a 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("Table Created.....\n");

   $stmt = $con -> prepare( "SELECT * FROM Test");

   //Executing the statement
   $stmt->execute();

   //Storing the result
   $stmt->store_result();
   print("Number of rows ".$stmt ->num_rows);

   //Freeing the resultset memory
   $stmt->free_result();

   //Closing the statement
   $stmt->close();

   //Closing the connection
   $con->close();
?>

Cela produira le résultat suivant -

Table Created.....
Number of rows: 3