<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Free result memory</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-field-type.html">mysql_field_type</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mysql-get-client-info.html">mysql_get_client_info</a></div> <div class="up"><a href="ref.mysql.html">MySQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.mysql-free-result" class="refentry"> <div class="refnamediv"> <h1 class="refname">mysql_free_result</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_free_result</span> — <span class="dc-title">Free result memory</span></p> </div> <div id="function.mysql-free-result-refsynopsisdiv"> <div class="warning"><strong class="warning">Warning</strong> <p class="para">This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the <a href="book.mysqli.html" class="link">MySQLi</a> or <a href="ref.pdo-mysql.html" class="link">PDO_MySQL</a> extension should be used. See also <a href="mysqlinfo.api.choosing.html" class="link">MySQL: choosing an API</a> guide and <a href="faq.databases.html#faq.databases.mysql.deprecated" class="link">related FAQ</a> for more information. Alternatives to this function include:</p> <ul class="simplelist"> <li class="member"> <span class="function"><a href="mysqli-result.free.html" class="function">mysqli_free_result()</a></span></li> <li class="member">Assign the value of <strong><code>NULL</code></strong> to the PDO object, or <span class="methodname"><a href="pdostatement.closecursor.html" class="methodname">PDOStatement::closeCursor()</a></span></li> </ul> </div> </div> <div class="refsect1 description" id="refsect1-function.mysql-free-result-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>mysql_free_result</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>mysql_free_result()</strong></span> will free all memory associated with the result identifier <em><code class="parameter">result</code></em>. </p> <p class="para"> <span class="function"><strong>mysql_free_result()</strong></span> 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. </p> </div> <div class="refsect1 parameters" id="refsect1-function.mysql-free-result-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter"> result</code></em></span><dd> <p class="para">The result <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> that is being evaluated. This result comes from a call to <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span>.</p></dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.mysql-free-result-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> <p class="para"> If a non-resource is used for the <em><code class="parameter">result</code></em>, an error of level E_WARNING will be emitted. It's worth noting that <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span> only returns a <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> for SELECT, SHOW, EXPLAIN, and DESCRIBE queries. </p> </div> <div class="refsect1 examples" id="refsect1-function.mysql-free-result-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1594"> <p><strong>Example #1 A <span class="function"><strong>mysql_free_result()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id,email FROM people WHERE id = '42'"</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$result</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'Could not run query: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">();<br /> exit;<br />}<br /></span><span style="color: #FF8000">/* Use the result, assuming we're done with it afterwards */<br /></span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Now we free up the result and continue on with our script */<br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'id'</span><span style="color: #007700">];<br />echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'email'</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.mysql-free-result-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> For backward compatibility, the following deprecated alias may be used: <span class="function"><strong>mysql_freeresult()</strong></span> </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.mysql-free-result-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.mysql-query.html" class="function" rel="rdfs-seeAlso">mysql_query()</a> - Send a MySQL query</span></li> <li class="member"> <span class="function"><a href="function.is-resource.html" class="function" rel="rdfs-seeAlso">is_resource()</a> - Finds whether a variable is a resource</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-field-type.html">mysql_field_type</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mysql-get-client-info.html">mysql_get_client_info</a></div> <div class="up"><a href="ref.mysql.html">MySQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>