CakeFest 2024: The Official CakePHP Conference

mysql_free_result

(PHP 4, PHP 5)

mysql_free_result結果保持用メモリを開放する

警告

この拡張モジュールは PHP 5.5.0 で非推奨になり、PHP 7.0.0 で削除されました。 MySQLi あるいは PDO_MySQL を使うべきです。詳細な情報は MySQL: API の選択 を参照ください。 この関数の代替として、これらが使えます。

説明

mysql_free_result(resource $result): bool

mysql_free_result() は、結果 ID result に関するすべてのメモリを開放します。

mysql_free_result() は、 スクリプト実行のメモリの使用量が多すぎると懸念される場合にのみ 必要になります。指定した結果 ID に関する全ての結果保持用メモリは、 スクリプトの実行後に自動的に開放されます。

パラメータ

result

評価された結果 リソース。この結果は、mysql_query() のコールにより得られたものです。

戻り値

成功した場合に true を、失敗した場合に false を返します。

result がリソースではなかった場合、 E_WARNING レベルのエラーが発生します。 mysql_query()resource を返すのは SELECT, SHOW, EXPLAIN, そして DESCRIBE の場合だけであることに注意しましょう。

例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;
}
/* 結果を利用する。ここでは、その後結果を利用したものと仮定する */
$row = mysql_fetch_assoc($result);

/* 結果を開放し、さらにスクリプトの処理を進める */
mysql_free_result($result);

echo
$row['id'];
echo
$row['email'];
?>

注意

注意:

下位互換のために、次の非推奨別名を使用してもいいでしょう。 mysql_freeresult()

参考

add a note

User Contributed Notes 3 notes

up
15
webmaster at bluesting dot co dot za
13 years ago
mysql_query() also returns a resource for "OPTIMIZE TABLE" statements!
up
16
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
-36
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