pg_close

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

pg_closeSchließt eine PostgreSQL-Verbindung

Beschreibung

pg_close(?PgSql\Connection $connection = null): true

pg_close() schließt die nicht-persistente Verbindung, die durch die connection-Instanz 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 PgSql\Lob-Instanzen gibt, sollten alle PgSql\Lob-Instanzen geschlossen werden, bevor die Verbindung geschlossen wird.

Parameter-Liste

connection

Eine PgSql\Connection-Instanz. Falls connection null ist, wird die Standardverbindung benutzt. Das ist die zuletzt mit pg_connect() oder pg_pconnect() aufgebaute Verbindung.

Warnung

Seit PHP 8.1.0 ist die Verwendung der Standardverbindung veraltet.

Rückgabewerte

Gibt immer true zurück.

Changelog

Version Beschreibung
8.2.0 Der Rückgabewert ist nun true vorher war es bool.
8.1.0 Der Parameter connection erwartet nun eine PgSql\Connection-Instanz; vorher wurde eine Ressource erwartet.
8.0.0 connection ist jetzt nullbar.

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