I am creating a PHP/MySQLi class for a university project and annoyingly they are using PHP version 5.2.6. I need my class to execute the query using prepared statements and give an array of results, all of which works on PHP > 5.3 but on 5.2.6 my get_result
is causing a fatal error. Is there any alternatives?
I have looked at bind_result
although there could be ANY number of fields in the statement which means I cannot use this function.
public function select($query, $data = NULL) {
$db = $this->connect();
$stmt = $db->prepare($query);
if(!is_null($data)) {
call_user_func_array(array($stmt, 'bind_param'), $this->query_params($data));
}
$stmt->execute();
$sqlResult = $stmt->get_result(); //fatal error on PHP < 5.3
$results = array();
while($row = $sqlResult->fetch_assoc()) {
$results[] = $row;
}
return $results;
}