I am new to all of this, so please be patient. I am trying to convert over to mysqli and searched the net for samples and now I am stuck on trying to free the binding results. Every example I saw always had 1 field in the binding results and later it was freed, but I have a query with a few fields and some how can't figure out how to clear the memory. Can anyone help me please. Also, is this 100% OOP or did I mix up procedural statements in it?
Code: Select all
<?php
require("dbcon.php");
// Check for errors
if(mysqli_connect_errno())
{
echo mysqli_connect_error();
}
// Create a prepared statement
if($stmt = $mysqli -> prepare ("SELECT id, username, password FROM users WHERE password=?"))
{
// Bind parameters s - String, b - Boolean, i - Integer etc
$password='123';
$stmt -> bind_param("s", $password);
// Execute it
$stmt -> execute();
// Bind result variables
$stmt->bind_result($id,$username,$password);
// Fetch the result of the query
while($stmt->fetch())
{
echo $id . ' - ' . $password . ' - ' . $username;
echo "<br />";
}
// Free the memory of the results
//mysqli_free_result($result);
// Close statement
$stmt -> close();
}
// Close connection
$mysqli -> close();
?>