The mysqli_free_result() function frees the memory associated with the result.
mysqli_free_result(result);
Parameter | Is Required | Description |
---|---|---|
result | Required. | Result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result() |
The following code retrieves rows from a resultset, then free the memory associated with the resultset.
<?php/*from ww w.j ava 2 s .c om*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT name FROM Emp";
if ($result=mysqli_query($con,$sql)){
while ($row=mysqli_fetch_row($result)){
printf ("%s (%s)\n",$row[0],$row[1]);
}
mysqli_free_result($result);// clear result set
}
mysqli_close($con);
?>