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

search for in the

pg_convert> <pg_connection_reset
Last updated: Fri, 20 Jun 2008

view this page in

pg_connection_status

(PHP 4 >= 4.2.0, PHP 5)

pg_connection_status — Lit le statut de la connexion PostgreSQL

Description

int pg_connection_status ( resource $connection )

pg_connection_status() retourne le statut de la connexion connection .

Liste de paramètres

connection

Ressource de connexion de base de données PostgreSQL.

Valeurs de retour

PGSQL_CONNECTION_OK ou PGSQL_CONNECTION_BAD.

Exemples

Exemple #1 Exemple avec pg_connection_status()

<?php
  $dbconn 
pg_connect("dbname=publisher") or die("Connexion impossible");
  
$stat pg_connection_status($dbconn);
  if (
$stat === PGSQL_CONNECTION_OK) {
      echo 
'Connexion ok';
  } else {
      echo 
'Connexion erronée';
  } 
?>



pg_convert> <pg_connection_reset
Last updated: Fri, 20 Jun 2008
 
add a note add a note User Contributed Notes
pg_connection_status
Mathieu De Zutter
02-Aug-2006 02:45
Being careful with the comparison operators is not enough:

<?php
if (pg_connection_status($link)===PGSQL_CONNECTION_BAD)
  
reconnect($link);
?>

The reconnect won't be trigged when $link is null.

The manual is just wrong, there are three return values: PGSQL_CONNECTION_OK, PGSQL_CONNECTION_BAD, null
david dot tulloh at infaze dot com dot au
15-Jun-2005 05:33
I think zytox is incorrect, at least in PHP 5.0.4.
It returns null, but you have to be careful with your comparison operators.

As an example:
<?php
unset($null);
if (
pg_connection_status($null)===PGSQL_CONNECTION_OK)
    echo
'this is not called';
if (
pg_connection_status($null)==PGSQL_CONNECTION_OK)
    echo
'this is called because NULL==0 is true';
?>
zytox at hotmail dot com
02-Apr-2005 08:34
If the connection variable is NULL this function returns 0 in PHP 5.0.2. Havent figured out any more erratic values for the connection variable but be careful.

pg_convert> <pg_connection_reset
Last updated: Fri, 20 Jun 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites