略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pg_close

2024-04-27

pg_close

(PHP 4, PHP 5, PHP 7, PHP 8)

pg_close关闭一个 PostgreSQL 连接

说明

pg_close(resource $connection = ?): bool

pg_close() 关闭由所给资源 connection 指定的到 PostgreSQL 数据库的非持久连接。

注意:

使用 pg_close() 并不很必要,因为非持久连接在本脚本执行结束后会自动关闭。

如果在此连接中打开了 large object 资源,则在关闭所有 large object 资源之前不要关闭连接。

参数

connection

PostgreSQL database connection resource. When connection is not present, the default connection is used. The default connection is the last connection made by pg_connect() or pg_pconnect().

返回值

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

范例

示例 #1 pg_close() 例子

<?php
$dbconn 
pg_connect("host=localhost port=5432 dbname=mary")
   or die(
"Could not connect");
echo 
"Connected successfully";
pg_close($dbconn);
?>

以上例程会输出:

Connected successfully

参见

add a noteadd a note

User Contributed Notes 2 notes

up
5
amays
16 years ago
pg_close(...) will not technically close a persistent connection but instead returns it back to the connection pool thus giving you the desired effect of having the connection closed within your script.

http://www.sitepoint.com/article/accessing-postgresql-php/3

best wishes to all.
up
2
mark at redbrick dot dcu dot ie
19 years ago
This function closes the current database connection specified by a handle returned from a pg_connect() call.

<?php
    $pgsql_conn
= pg_connect("dbname=mark host=localhost");

    if (
$pgsql_conn) {
        print
"Successfully connected to: " . pg_host($pgsql_conn) . "<br/>\n";
    } else {
        print
pg_last_error($pgsql_conn);
        exit;
    }

   
// Do database stuff here.

   
if(!pg_close($pgsql_conn)) {
        print
"Failed to close connection to " . pg_host($pgsql_conn) . ": " .
      
pg_last_error($pgsql_conn) . "<br/>\n";
    } else {
        print
"Successfully disconnected from database";
    }
?>

Of course you normally wouldn't print a message. 

Regards, --mark

官方地址:https://www.php.net/manual/en/function.pg-close.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3