Here\'s my code:
include \'conn.php\';
$conn = new Connection();
$query = \'SELECT EmailVerified, Blocked FROM users WHERE Email = ? AND SLA = ? AND `Passwo
for those searching for an alternative to $result = $stmt->get_result()
I've made this function which allows you to mimic the $result->fetch_assoc()
but using directly the stmt object:
function fetchAssocStatement($stmt)
{
if($stmt->num_rows>0)
{
$result = array();
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params[] = &$result[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
if($stmt->fetch())
return $result;
}
return null;
}
as you can see it creates an array and fetches it with the row data, since it uses $stmt->fetch()
internally, you can call it just as you would call mysqli_result::fetch_assoc
(just be sure that the $stmt
object is open and result is stored):
//mysqliConnection is your mysqli connection object
if($stmt = $mysqli_connection->prepare($query))
{
$stmt->execute();
$stmt->store_result();
while($assoc_array = fetchAssocStatement($stmt))
{
//do your magic
}
$stmt->close();
}