pg_connection_status

(PHP 4 >= 4.2.0, PHP 5)

pg_connection_status Get connection status

Description

int pg_connection_status ( resource $connection )

pg_connection_status() returns the status of the specified connection.

Parameters

connection

PostgreSQL database connection resource.

Return Values

PGSQL_CONNECTION_OK or PGSQL_CONNECTION_BAD.

Examples

Example #1 pg_connection_status() example

<?php
  $dbconn 
pg_connect("dbname=publisher") or die("Could not connect");
  
$stat pg_connection_status($dbconn);
  if (
$stat === PGSQL_CONNECTION_OK) {
      echo 
'Connection status ok';
  } else {
      echo 
'Connection status bad';
  }    
?>

See Also

Коментарии

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.
2005-04-02 13:34:04
http://php5.kiev.ua/manual/ru/function.pg-connection-status.html
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';
?>
2005-06-14 23:33:01
http://php5.kiev.ua/manual/ru/function.pg-connection-status.html
Автор:
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
2006-08-02 08:45:40
http://php5.kiev.ua/manual/ru/function.pg-connection-status.html
Автор:
The wiki page doesn't currently reflect that, but if you're passing PGSQL_CONNECT_ASYNC to pg_connect, creating the connection won't block and transitions through extra states expressed by those constants.

PGSQL_CONNECTION_AUTH_OK
PGSQL_CONNECTION_AWAITING_RESPONSE
PGSQL_CONNECTION_MADE
PGSQL_CONNECTION_SETENV
PGSQL_CONNECTION_SSL_STARTUP
PGSQL_CONNECTION_STARTED
2018-03-30 16:38:30
http://php5.kiev.ua/manual/ru/function.pg-connection-status.html

    Поддержать сайт на родительском проекте КГБ