I'm using my own class for database queries, extending mysqli:
class iDatabase extends mysqli
{
public $errorMsg;
private $totalQueries;
private $stmt;
public function __construct()
{
parent::__construct( 'localhost', 'asd', 'asd', 'asd' );
if ( mysqli_connect_errno() )
{
$this->errorMsg = 'Could not connect to server.<br /><i>' . mysqli_connect_error() . '</i>.';
return;
}
parent::query( 'SET NAMES utf8' );
}
}
However I'm running into trouble when executing queries and getting back results. I'm using prepared statements, but the way values and results are bound is confusing me. After a bit of research I came up with this function that accepts the query and parameters:
public function psQuery( $query, $params )
{
$this->stmt = parent::prepare( $query );
call_user_func_array( array($this->stmt,'bind_param'), $params );
$this->stmt->execute();
}
My question is, what is the best way to get results back from this? I need to use bind_result, then fetch each row, then close the statement. I'd prefer to just get an associative array for each row - is that possible?