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

search for in the

pg_tty> <pg_trace
[edit] Last updated: Fri, 25 May 2012

view this page in

pg_transaction_status

(PHP 5 >= 5.1.0)

pg_transaction_statusサーバー上で実行中のトランザクションの状態を返す

説明

int pg_transaction_status ( resource $connection )

サーバー上で実行中のトランザクションの状態を返します。

警告

PostgreSQL 7.3 サーバーで autocommit を off に 設定している場合、pg_transaction_status() は 不正確な値を返します。サーバー側での自動コミット機能は非推奨と されており、最近のバージョンのサーバーでは存在しません。

パラメータ

connection

PostgreSQL データベースの接続リソース。

返り値

PGSQL_TRANSACTION_IDLE(アイドル状態)、 PGSQL_TRANSACTION_ACTIVE(コマンドの実行中)、 PGSQL_TRANSACTION_INTRANS(正常なトランザクション内でアイドル状態)、 あるいは PGSQL_TRANSACTION_INERROR(失敗したトランザクション内でアイドル状態) のいずれかを返します。 接続が異常な場合は PGSQL_TRANSACTION_UNKNOWN を返します。 PGSQL_TRANSACTION_ACTIVE が返されるのは、クエリを サーバーに送信した後まだそれが完了していない場合のみです。

例1 pg_transaction_status() の例

<?php
  $dbconn 
pg_connect("dbname=publisher") or die("Could not connect");
  
$stat pg_transaction_status($dbconn);
  if (
$stat === PGSQL_TRANSACTION_UNKNOWN) {
      echo 
'Connection is bad';
  } else if (
$stat === PGSQL_TRANSACTION_IDLE) {
      echo 
'Connection is currently idle';
  } else {
      echo 
'Connection is in a transaction state';
  }    
?>



add a note add a note User Contributed Notes pg_transaction_status
hofman dot tomas at gmail dot com 07-Jul-2010 07:52
Exact values of constants:

PGSQL_TRANSACTION_IDLE = 0
PGSQL_TRANSACTION_ACTIVE = 1
PGSQL_TRANSACTION_INTRANS = 2
PGSQL_TRANSACTION_INERROR = 3
PGSQL_TRANSACTION_UNKNOWN = 4
btherl at yahoo dot com dot au 17-Jul-2006 01:27
This function is implemented in C, so there's no way to mimic it in SQL for older versions of PHP.  But you can mimic some of the functionality by using a wrapper which keeps track of when you begin and commit/rollback transactions.

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