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, 24 May 2013

view this page in

pg_close

(PHP 4, PHP 5)

pg_closeFecha uma conexão PostgreSQL

Descrição

bool pg_close ( resource $connection )

pg_close() fecha a conexão não persistente com servidor de banco de dados PostgreSQL associado ao recurso (resource) connection dado. Retorna TRUE em caso de sucesso ou FALSE em caso de falha.

Nota:

Normalmente, o uso de pg_close() não é necessário já que conexões não persistentes abertas são automaticamente fechadas ao final do processamento do script.

Exemplo #1 pg_close() example

<?php
      $dbconn 
pg_connect("host=localhost port=5432 dbname=mary")
          or die(
"Não foi possível conectar");
      print(
"Conexão bem sucedida");
      
pg_close($dbconn);
  
?>

Se existem recursos (resource) de objetos grandes (large objects) abertos na conexão, não feche a conexão antes de fechar todos os recursos relacionados com estes objetos.



pg_connect> <pg_client_encoding
[edit] Last updated: Fri, 24 May 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 | sitemap | contact | advertising | mirror sites