PHP MySQLi Prepared Statement: Fetch Not Returning Results for Joins
I forget where I copied it from (I think a user posted it on php.net) but this function for fetching results of prepared and normal MySQLi statements is not returning any results when used with statements that contain a simple INNER JOIN, at least the one I tried:

    function fetch($result){   
	$array = array();			
	if($result instanceof mysqli_stmt){
		$result->store_result();
		$variables = array();
		$data = array();
		$meta = $result->result_metadata();					
		while($field = $meta->fetch_field()){					
			$variables[] = &$data[$field->name];
		}				
		call_user_func_array(array($result, 'bind_result'), $variables);
		$i=0;								
		while($result->fetch()){									
			$array[$i] = array();
			foreach($data as $k=>$v)
			$array[$i][$k] = $v;
			$i++;					
		}				
	}elseif($result instanceof mysqli_result){
		while($row = $result->fetch_assoc())
		$array[] = $row;
	}			
	return $array;
}

I've been trying to use it like so (all these functions are methods of the class $database):

    function query($str, $values){					 			
	if($stmt=$this->sql->prepare($str)){					
		$types=$this->castArrayAsString($values); //returns a string of $values's types for bind_params				
		array_unshift($values, $types);			
		call_user_func_array(array(&$stmt, 'bind_param'), $this->makeValuesReferenced($values));						
		$stmt->execute();
		$result=$this->fetch($stmt); //the function I'm having problems with																			
		if(empty($result)){										
	    	$return=true;		    		
    	}else{
	    	$return=$result;
    	}		
		$stmt->close();			
	}else{
		echo $this->sql->error;
		$return=false;	
	}						
	return $return;				
}


This returns nothing:

$list=$database->query("SELECT a.field1, b.field2 FROM table1 AS a INNER JOIN table2 AS b ON a.id_table2=b.id WHERE a.someid=?", array($someid));

This works fine:

$list=$database->query("SELECT field1, field2 FROM table1 WHERE someid=?", array($someid));


If I print out the meta data from fetching the result, it shows that fields are selected, etc, but still gives no final results in the fetch() func.

Any help is appreciated,

Thanks
PHP MySQLi Prepared Statement: Fetch Not Returning Results for Joins
===

I forget where I copied it from (I think a user posted it on php.net) but this function for fetching results of prepared and normal MySQLi statements is not returning any results when used with statements that contain a simple INNER JOIN, at least the one I tried:

    function fetch($result){   
	$array = array();			
	if($result instanceof mysqli_stmt){
		$result->store_result();
		$variables = array();
		$data = array();
		$meta = $result->result_metadata();					
		while($field = $meta->fetch_field()){					
			$variables[] = &$data[$field->name];
		}				
		call_user_func_array(array($result, 'bind_result'), $variables);
		$i=0;								
		while($result->fetch()){									
			$array[$i] = array();
			foreach($data as $k=>$v)
			$array[$i][$k] = $v;
			$i++;					
		}				
	}elseif($result instanceof mysqli_result){
		while($row = $result->fetch_assoc())
		$array[] = $row;
	}			
	return $array;
}

I've been trying to use it like so (all these functions are methods of the class $database):

    function query($str, $values){					 			
	if($stmt=$this->sql->prepare($str)){					
		$types=$this->castArrayAsString($values); //returns a string of $values's types for bind_params				
		array_unshift($values, $types);			
		call_user_func_array(array(&$stmt, 'bind_param'), $this->makeValuesReferenced($values));						
		$stmt->execute();
		$result=$this->fetch($stmt); //the function I'm having problems with																			
		if(empty($result)){										
	    	$return=true;		    		
    	}else{
	    	$return=$result;
    	}		
		$stmt->close();			
	}else{
		echo $this->sql->error;
		$return=false;	
	}						
	return $return;				
}


This returns nothing:

$list=$database->query("SELECT a.field1, b.field2 FROM table1 AS a INNER JOIN table2 AS b ON a.id_table2=b.id WHERE a.someid=?", array($someid));

This works fine:

$list=$database->query("SELECT field1, field2 FROM table1 WHERE someid=?", array($someid));


If I print out the meta data from fetching the result, it shows that fields are selected, etc, but still gives no final results in the fetch() func.

Any help is appreciated,

Thanks