PHP Doku:: Gibt den Verbindungsstatus zurück - function.pg-connection-status.html

Verlauf / Chronik / History: (38) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenPostgreSQLPostgreSQL-Funktionenpg_connection_status

Ein Service von Reinhard Neidl - Webprogrammierung.

PostgreSQL-Funktionen

<<pg_connection_reset

pg_convert>>

pg_connection_status

(PHP 4 >= 4.2.0, PHP 5)

pg_connection_status Gibt den Verbindungsstatus zurück

Beschreibung

int pg_connection_status ( resource $connection )

pg_connection_status() gibt den Status der angegebenen connection zurück.

Parameter-Liste

connection

PostgreSQL Verbindungskennung.

Rückgabewerte

PGSQL_CONNECTION_OK oder PGSQL_CONNECTION_BAD.

Beispiele

Beispiel #1 pg_connection_status() Beispiel

<?php
  $dbconn 
pg_connect("dbname=publisher") or die("Konnte keine Verbindung aufbauen");
  
$stat pg_connection_status($dbconn);
  if (
$stat === PGSQL_CONNECTION_OK) {
      echo 
'Verbindungsstatus ok';
  } else {
      echo 
'Verbindungsstatus bad';
  }    
?>

Siehe auch


3 BenutzerBeiträge:
- Beiträge aktualisieren...
Mathieu De Zutter
2.08.2006 14: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.06.2005 5: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
2.04.2005 20: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.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)