PHP 8.4.1 Released!

pg_free_result

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_free_result释放查询结果占用的内存

说明

pg_free_result(PgSql\Result $result): bool

pg_free_result() 释放与指定 PgSql\Result 实例关联的内存和数据。

仅当脚本执行期间的内存消耗成为问题时才需要调用此函数。否则,所有结果内存将在脚本结束时自动释放。

注意:

本函数以前的名字为 pg_freeresult()

参数

result

PgSql\Result 实例,由 pg_query()pg_query_params() 或者 pg_execute()(等)返回。

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.1.0 现在 result 参数接受 PgSql\Result 实例,之前接受 resource

示例

示例 #1 pg_free_result() 示例

<?php
$db
= pg_connect("dbname=users user=me") || die();

$res = pg_query($db, "SELECT 1 UNION ALL SELECT 2");

$val = pg_fetch_result($res, 1, 0);

echo
"First field in the second row is: ", $val, "\n";

pg_free_result($res);
?>

以上示例会输出:

First field in the second row is: 2

参见

  • pg_query() - 执行查询
  • pg_query_params() - Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text
  • pg_execute() - Sends a request to execute a prepared statement with given parameters, and waits for the result

添加备注

用户贡献的备注 1 note

up
2
Stefan W
11 years ago
You do NOT need to call pg_free_result() on every result resource you create.
When result resources go out of scope, they are garbage collected just like everything else.
Unless you're hoarding your results somewhere, you can basically ignore this function.

Here's a little test you can run to confirm this: http://pastebin.com/ghw1PHuE
To Top