pg_close

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

pg_closeSchließt eine PostgreSQL-Verbindung

Beschreibung

pg_close ( resource $connection = ? ) : bool

pg_close() schließt die nicht-persistente Verbindung, die durch die Kennung connection bezeichnet wird.

Hinweis:

Die Verwendung von pg_close() ist normalerweise nicht notwendig, da geöffnete, nicht-persistente Verbindungen automatisch geschlossen werden, wenn das Skript beendet wird.

Falls es auf dieser Verbindung geöffnete Large Objects gibt, sollten Sie diese schließen, bevor Sie die Verbindung schließen.

Parameter-Liste

connection

PostgreSQL-Verbindungkennung. Falls connection nicht angegeben wurde, wird die zuletzt mit pg_connect() oder pg_pconnect() geöffnete Verbindung benutzt.

Rückgabewerte

Gibt bei Erfolg true zurück. Im Fehlerfall wird false zurückgegeben.

Beispiele

Beispiel #1 pg_close()-Beispiel

<?php
$dbconn 
pg_connect("host=localhost port=5432 dbname=mary")
   or die(
"Keine Verbindung möglich");
echo 
"Verbindung hergestellt";
pg_close($dbconn);
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Verbindung hergestellt

Siehe auch

add a note add a note

User Contributed Notes 2 notes

up
5
amays
18 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
21 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
To Top