mysqli_free_result

(PHP 5)

mysqli_free_result

(no version information, might be only in CVS)

result->free -- Frees the memory associated with a result

Description

Procedural style:

void mysqli_free_result ( mysqli_result result )

Object oriented style (method):

class mysqli_result {

void free ( void )

}

The mysqli_free_result() function frees the memory associated with the result represented by the result parameter, which was allocated by mysqli_query(), mysqli_store_result() or mysqli_use_result().

注: You should always free your result with mysqli_free_result(), when your result object is not needed anymore.

返回值

This function doesn't return any value.


add a note add a note User Contributed Notes
jon at fuck dot org
12-Jan-2006 02:39
better to wrap the result object in its own class, separate from the connection object wrapper: __destruct() can be used to automatically free the result set. this isn't a terribly new design pattern, either.

just be sure to destroy your result object before you make another query with the same DBI instance if you happen to change the flag to MYSQLI_USE_RESULT. actually, you'll find if you write the code with or without a wrapper class that it looks rather the same.

this code also allows you to track what kind of result set you've created by passing the flag around, although i don't think i'd ever need to use that myself.

class DBI
{
  function __construct()
  {
   $this->dbconn = new mysqli(...);
  }

  function query($sql, $flag = MYSQLI_STORE_RESULT)
  {
   $result = $this->dbconn->query($sql, $flag);
   return new RecordSet($result, $flag);
  }
};

class RecordSet
{
  function __construct($res, $flag = MYSQLI_STORE_RESULT)
  {
   $this->result = $res;
   $this->flag = $flag;
  }

  function __destruct()
  {
   $this->result->free();
  }
};
austregecilio at yahoo dot com dot br
16-Jun-2005 09:52
Using mysqli_free_result in a class, should be like this:

class db{
  .
  .
  .
  public function db_free_res($obj){
   mysqli_free_result($obj);
  }
  .
  .
  .
}

The code in .PHP file:

$obj_con=new db;
$res=$obj_con->db_query("select * from imgs");
$obj_con->db_free_res($res);