Thanks to everyone that leaves notes, without them I would not be able to do what I do. I wrote this function with help from notes on this page and others.
I did not have mysqlnd available to me, but wanted to be able to get_result() of a query as an object.
PLEASE NOTE: I am not an expert at PHP
Heres an example of using my get_result() to login users
<?php
function login($email, $password){
require 'connect_db.php';
$query = $sql->stmt_init();
if($query->prepare("SELECT CustomerId, Password, Admin FROM users WHERE Email = ?")){
$query->bind_param("s",$email);
$result = get_result($query); if($result != NULL){
$user = $result[0];
if(password_verify($password, $user->Password)){
$_SESSION['user_id'] = $user->CustomerId;
if($user->Admin == 1){
$_SESSION['admin'] = true;
}
$sql->close();
return true;
}
}
}
$sql->close();
return false;
}
function get_result($stmt){
$stmt->execute(); $stmt->store_result(); $num_rows = $stmt->num_rows; $results = NULL;
if($num_rows > 0){
$meta = $stmt->result_metadata();
$bind_code = "return mysqli_stmt_bind_result(\$stmt, ";
while($_field = $meta->fetch_field()){
$bind_code .= "\$row[\"".$_field->name."\"], ";
}
$bind_code = substr_replace($bind_code,");", -2);
if(!eval($bind_code)) {
$stmt->close();
return NULL;
}
for($i=0;$i<$num_rows;$i++){
$stmt->data_seek($i);
$stmt->fetch();
foreach($row as $key=>$value){
$_result[$key] = $value;
}
$results[$i] = (object)$_result;
}
}
$stmt->close();
return $results;
}
?>