I'm trying to make my own "Database" class for MySQLi, it's the classic class that coomunicate with database, so into my web application I can do (for example)
$user = $database->select($connection, "SELECT * FROM user");
So I wrote the function (this is the part where there are no parameters in the query)
public function select($link, $query, $types, $arrayValues)
{
$set = array(); //this is what the function will return
$statement;
if($types == null && $arrayValues == null)
{
$statement = $link->prepare($query);
if($statement->execute())
{
$statement->store_result();
$meta = $statement->result_metadata();
$fileds = array();
$results = array();
//put into the array the exact number of variables for call_user_func_array
while($field = $meta->fetch_field())
{
$var = $field->name;
$$var = null;
$fields[$var] = &$$var;
}
$fieldCount = $statement->field_count;
call_user_func_array(array($statement,'bind_result'),$fields);
while($statement->fetch())
{
$set[] = $fields;
}
echo '<pre>';
print_r($set);
echo '</pre>';
}
}
else
{
part of the function where there are parameters in the query
}
return $set;
}
Now the problem is that $set (which must be returned) is an array, but all the values of the array are the same: the last record I extracted with the query. Why? I'm going crazy