downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

pg_connect> <pg_client_encoding
[edit] Last updated: Fri, 07 Jun 2013

view this page in

pg_close

(PHP 4, PHP 5)

pg_closeCierra una conexión PostgreSQL

Descripción

bool pg_close ([ resource $connection ] )

pg_close() Cierra una conexión no persistente a una base de datos PostgreSQL asociada con el recurso de la connection.

Nota:

Usar pg_close() generalmente no es necesario, cuando se abren conexiones no persitentes estas se cierran automaticamente al terminar el script.

Si hay objetos grandes abiertos en el recurso de la conexión, no cierre la conexión, antes cierre todos los objetos grandes en el recurso.

Parámetros

connection

Es el recurso de conexión de base de datos PostgreSQL. Cuando el parametro connection no está presente, se usa la conexión por defecto. La conexión por defecto es la última conexión hecha por pg_connect() o pg_pconnect().

Valores devueltos

Devuelve TRUE en caso de éxito o FALSE en caso de error.

Ejemplos

Ejemplo #1 Ejemplo de pg_close()

<?php
$dbconn 
pg_connect("host=localhost port=5432 dbname=mary")
   or die(
"No se pudo conectar");
echo 
"Conectado con éxito";
pg_close($dbconn);
?>

El resultado del ejemplo sería:

Conectado con exito

Ver también



pg_connect> <pg_client_encoding
[edit] Last updated: Fri, 07 Jun 2013
 
add a note add a note User Contributed Notes pg_close - [3 notes]
up
1
amays
7 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
0
mark at redbrick dot dcu dot ie
10 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
up
-1
nox at macports dot org
5 years ago
An E_WARNING level warning is generated if the supplied argument is not a valid postgresql link resource.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites