• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • pg_free_result()

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

    释放查询结果占用的内存

    说明

    pg_free_result(resource $result): bool

    pg_free_result()仅在当你担心脚本执行时占用了过多内存时调用。脚本执行完毕后所有的查询结果占用的内存都会被自动释放。不过如果你确认在脚本中不会再用到查询结果了,你可以用$result作为参数调用pg_free_result()来释放有关的内存。成功时返回TRUE,或者在失败时返回FALSE

    Note:

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

    参见pg_query()。

    参数

    $result

    PostgreSQL query result resource, returned by pg_query(),pg_query_params() or pg_execute()(among others).

    返回值

    成功时返回TRUE,或者在失败时返回FALSE

    范例

    Example #1 pg_free_result() example

    <?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
    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

    上篇:pg_flush()

    下篇:pg_get_notify()