mysql_query() also returns a resource for "OPTIMIZE TABLE" statements!
(PHP 4, PHP 5)
mysql_free_result — 질의결과를 메모리에서 해제
$result
)
mysql_free_result()는 result
지시자와 관련된 점유 메모리를 해제한다.
mysql_free_result()는 결과 집합으로부터 질의에 사용되고 있는 메모리의 크기가 커서 문제가 발생할 수 있을 때 사용된다. 모든 연관된 결과 메모리는 스크립트 실행이 종료되면 메모리에서 자동적으로 해지된다.
성공 시 TRUE
를, 실패 시 FALSE
를 반환합니다.
result
에 비-자원(non-resource) 변수가 사용이 되면,
E_WARNING 등급의 에러가 발생될 것이다.
이것은 SELECT, SHOW, EXPLAIN, DESCRIBE 질의로 resource를
반환하는 mysql_query()만으로는 의미가 없다.
Example #1 mysql_free_result() 예제
<?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'];
?>
Note:
하위 호환을 위하여, 다음의 권장하지 않는 별칭을 사용할 수 있습니다: mysql_freeresult()
mysql_query() also returns a resource for "OPTIMIZE TABLE" statements!
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).