Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : MySQL Functions : mysql_free_result

mysql_free_result

Free result memory (PHP 4, PHP 5, PECL mysql:1.0)
bool mysql_free_result ( resource result )

Example 1441. 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'];
?>

Code Examples / Notes » mysql_free_result

macronesia

You not need to use this if you are using PHP 4.
The comment below this comment may explain why it's actually costing more memory.


mdeininger

yes, i encountered that too. as far as i could tell, that's because the script is stored in memory after being compiled and that's as much more memory as it needs for a call to that function.
if you always get lotsa data in your results, using this function will decrease memory usage tho, unless you use non-buffered queries (which are preferable unless you absolutely *have* to use mysql_seek(), or you need to do another query while the last one hasn't finished reporting back, as they can provide a small speedup)


joachim kruyswijk

Using this function may actually increase the amount of memory used. In my case, the script used 208 bytes less memory when *not* using mysql_free_result().
Check for yourself: call memory_get_usage() at the end of the script.


21-nov-2006 10:53

If you're seeing warnings like "Warning: Unknown: 6 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0" and want to turn them off, set mysql.trace_mode = Off in your php.ini

nairebis

ALWAYS use this function! I just encountered a bug in my code where I forgot to use this function. I also happen to be using mysql_pconnect() for a persistent connection. If you forget to free the result, it can hold the old result set open indefinitely within the HTTP process.
The upshot (in my application) was that I did updates that happened in a different HTTP process, but they mysteriously didn't show up in another HTTP process. After panicking that MySQL had mysterious data corruption and/or synchronization problems, I traced it back to this where an old result set was held open.


Change Language


Follow Navioo On Twitter
mysql_affected_rows
mysql_change_user
mysql_client_encoding
mysql_close
mysql_connect
mysql_create_db
mysql_data_seek
mysql_db_name
mysql_db_query
mysql_drop_db
mysql_errno
mysql_error
mysql_escape_string
mysql_fetch_array
mysql_fetch_assoc
mysql_fetch_field
mysql_fetch_lengths
mysql_fetch_object
mysql_fetch_row
mysql_field_flags
mysql_field_len
mysql_field_name
mysql_field_seek
mysql_field_table
mysql_field_type
mysql_free_result
mysql_get_client_info
mysql_get_host_info
mysql_get_proto_info
mysql_get_server_info
mysql_info
mysql_insert_id
mysql_list_dbs
mysql_list_fields
mysql_list_processes
mysql_list_tables
mysql_num_fields
mysql_num_rows
mysql_pconnect
mysql_ping
mysql_query
mysql_real_escape_string
mysql_result
mysql_select_db
mysql_set_charset
mysql_stat
mysql_tablename
mysql_thread_id
mysql_unbuffered_query
eXTReMe Tracker