What is the importance of using:
$stmt->free_result();
$stmt->close();
After a database call using prepared statments like this:
$mysqli=new mysqli("database", "db", "pass", "user");
$stmt = $mysqli->prepare("SELECT email FROM users WHERE id=? ");
$stmt->bind_param('i',$_SESSION['id']);
$stmt->execute();
$stmt->bind_result($email);
while($stmt->fetch()){
echo $email;
}
$stmt->free_result(); //why do i need this?
$stmt->close(); //why do i need this?
Im asking because I do not see any noticeable performance degradation without them. Are those commands usually only used for when I store the result using:
$stmt->store_result();
Like this:
$mysqli=new mysqli("database", "db", "pass", "user");
$stmt = $mysqli->prepare("SELECT email FROM users WHERE id=? ");
$stmt->bind_param('i',$_SESSION['id']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($email);
while($stmt->fetch()){
echo $email;
}
$stmt->free_result(); //why do i need this?
$stmt->close(); //why do i need this?
Ultimately the question comes down to when is the appropriate time to use freeresult() and close()?