<!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>Send an SQL query to MySQL without fetching and buffering the result rows.</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-thread-id.html">mysql_thread_id</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.mysqli.html">Mysqli</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-unbuffered-query" class="refentry"> <div class="refnamediv"> <h1 class="refname">mysql_unbuffered_query</h1> <p class="verinfo">(PHP 4 >= 4.0.6, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_unbuffered_query</span> — <span class="dc-title">Send an SQL query to MySQL without fetching and buffering the result rows.</span></p> </div> <div id="function.mysql-unbuffered-query-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">See: <a href="mysqlinfo.concepts.buffering.html" class="link">Buffered and Unbuffered queries</a></li> </ul> </div> </div> <div class="refsect1 description" id="refsect1-function.mysql-unbuffered-query-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>mysql_unbuffered_query</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span> [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code><span class="initializer"> = NULL</span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>mysql_unbuffered_query()</strong></span> sends the SQL query <em><code class="parameter">query</code></em> to MySQL without automatically fetching and buffering the result rows as <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span> does. This saves a considerable amount of memory with SQL queries that produce large result sets, and you can start working on the result set immediately after the first row has been retrieved as you don't have to wait until the complete SQL query has been performed. To use <span class="function"><strong>mysql_unbuffered_query()</strong></span> while multiple database connections are open, you must specify the optional parameter <em><code class="parameter">link_identifier</code></em> to identify which connection you want to use. </p> </div> <div class="refsect1 parameters" id="refsect1-function.mysql-unbuffered-query-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">query</code></em></span> <dd> <p class="para"> The SQL query to execute. </p> <p class="para"> Data inside the query should be <a href="function.mysql-real-escape-string.html" class="link">properly escaped</a>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter"> link_identifier</code></em></span><dd> <p class="para">The MySQL connection. If the link identifier is not specified, the last link opened by <span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span> is assumed. If no such link is found, it will try to create one as if <span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span> was called with no arguments. If no connection is found or established, an <strong><code>E_WARNING</code></strong> level error is generated.</p></dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.mysql-unbuffered-query-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> For SELECT, SHOW, DESCRIBE or EXPLAIN statements, <span class="function"><strong>mysql_unbuffered_query()</strong></span> returns a <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> on success, or <strong><code>FALSE</code></strong> on error. </p> <p class="para"> For other type of SQL statements, UPDATE, DELETE, DROP, etc, <span class="function"><strong>mysql_unbuffered_query()</strong></span> returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on error. </p> </div> <div class="refsect1 notes" id="refsect1-function.mysql-unbuffered-query-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The benefits of <span class="function"><strong>mysql_unbuffered_query()</strong></span> come at a cost: you cannot use <span class="function"><a href="function.mysql-num-rows.html" class="function">mysql_num_rows()</a></span> and <span class="function"><a href="function.mysql-data-seek.html" class="function">mysql_data_seek()</a></span> on a result set returned from <span class="function"><strong>mysql_unbuffered_query()</strong></span>, until all rows are fetched. You also have to fetch all result rows from an unbuffered SQL query before you can send a new SQL query to MySQL, using the same <em><code class="parameter">link_identifier</code></em>. </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.mysql-unbuffered-query-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> </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-thread-id.html">mysql_thread_id</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.mysqli.html">Mysqli</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>