mysql_free_result

(PHP 4, PHP 5)

mysql_free_resultLibera um resultado da memória

Descrição

mysql_free_result ( resource $result ) : bool

mysql_free_result() irá liberar toda a memória associada ao identificador de resultado result.

mysql_free_result() apenas precisa ser chamada se você esta preocupado sobre quanta memória esta sendo usada em consultas que retornam grandes conjuntos de resultados. Toda a memória associada a um resultado é automaticamente liberada ao final da execução do script.

Parâmetros

result

O resultado tipo resource que está sendo avaliado. Esse resultado é original de uma chamada a mysql_query().

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Se não for usado um recurso para result, um erro de nível E_WARNING será emitido. É importante notar que mysql_query() apena retorna um resource para consultas SELECT, SHOW, EXPLAIN, e DESCRIBE.

Exemplos

Exemplo #1 Um exemplo mysql_free_result()

<?php
$result 
mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!
$result) {
    echo 
'Não foi possível executar a consulta: ' 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'];
?>

Notas

Nota:

Para compatibilidade com versões anteriores, o seguinte apelido obsoleto pode ser usado: mysql_freeresult()

Veja Também

add a note add a note

User Contributed Notes 3 notes

up
12
admin at ifyouwantblood dot de
16 years ago
yes this function may increase the memory usage if you use unbuffered querys and if you have not fetched all the data from mysql. in this case the mysql api has a problem: you want to free the result but do not want to close the connection. now mysql will only accept another query if all data has been fetched, so the api now must fetch the rest of the data when calling mysql_free_result().

so only use unbuffered querys if you fetch all the data (and need it).
up
11
webmaster at bluesting dot co dot za
13 years ago
mysql_query() also returns a resource for "OPTIMIZE TABLE" statements!
up
-29
Anonymous
17 years ago
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
To Top