MySQLi Extend Example

By sean on Dec 10, 2010

This is a simple MySQLi extender example. You instantiate this class just as you would MySQLi.

$mysql = new mysqli_db('dbhost', 'dbuser', 'dbpass', 'dbname');

The multi_fetch_array() function essentially allows you to preform multiple queries. This is particularly handy when needing to call multiple stored procedures concurrently.

$m[] = sprintf('CALL fetchUserInfo(\'%s\')', $username);
$m[] = sprintf('CALL fetchUserActivity(\'%s\')', $username);
$result = $mysql->multi_fetch_array( implode(';', $m) );
class mysqli_db extends mysqli {
  public function fetch_array($sql) {
    $query = parent::query($sql);
    if ($query) {
      while( $result = $query->fetch_assoc() ) $return[] = $result;
    return ( (isset($return)) ? $return : false );

  public function multi_fetch_array($sql) {
    if (parent::multi_query($sql)) {
      do {
        if ($result = parent::store_result()) {
          while ($row = $result->fetch_assoc()) $return[] = $row;
      } while (parent::next_result());
    return $return;


Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.