search for in the  
<mysql_field_typemysql_get_client_info>
Last updated: Thu, 19 May 2005

mysql_free_result

(PHP 3, PHP 4, PHP 5)

mysql_free_result -- Free result memory

Description

bool mysql_free_result ( resource result )

mysql_free_result() will free all memory associated with the result identifier result.

mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution.

Parameters

result

The result resource that is being evaluated. This result comes from a call to mysql_query().

Return Values

Returns TRUE on success or FALSE on failure.

If a non-resource is used for the result, an error of level E_WARNING will be emitted. It's worth noting that mysql_query() only returns a resource for SELECT, SHOW, EXPLAIN, and DESCRIBE queries.

Examples

Example 1. A mysql_free_result() example

<?php
$result
= mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!
$result) {
   echo
'Could not run query: ' . mysql_error();
   exit;
}
/* Use the result, assuming we're done with it afterwords */
$row = mysql_fetch_assoc($result);

/* Now we free up the result and continue on with our script */
mysql_free_result($result);

echo
$row['id'];
echo
$row['email'];
?>

Notes

Note: For downward compatibility, the following deprecated alias may be used: mysql_freeresult()



User Contributed Notes
mysql_free_result
marcelo at orionlab dot net
01-Sep-2004 06:28
A very simple example:

<?php

// author: marcelo santos araujo
// marcelo at orionlab dot net

@mysql_connect("host","user","password");
@
mysql_select_db("database");

$simple_query = @mysql_query("SELECT * FROM login;");

// using mysql_free_result()
// managing memory

@mysql_free_result($simple_query);

?>
steve at stevedix dot de
06-Feb-2003 05:58
Godyvdb below is making an incorrect assumption, which may confuse.

When you call a query, you are returned a handle, which points to a set of results and the associated variables for it.  When you call free_result with that handle it will do a garbage - collection upon the result and associated variables, freeing up the memory.

What it WON'T do, and this is what Godyvdb is assuming, is optimise memory space by freeing all memory taken up by similar queries.  In his example
 
$myhandle=mysql_query("....");
mysql_free_result(mysql_query("...."));

all he does is makes another query to the database, generates a new handle, then immediately frees up the space allocated to the result.

If you wish to free up memory, then you can only do so by quoting the correct handle. You cannot generate a new handle to an existing query by the use of mysql_query.

eg.

$myhandle = mysql_query("....");
$anotherhandle =mysql_query("....");
mysql_free_result($myhandle);

$anotherhandle will still point to an existing set of results, whilst $myhandle won't.  The two handles are not related.

<mysql_field_typemysql_get_client_info>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT