pg_transaction_status

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

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

説明

pg_transaction_status(resource $connection): int

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

警告

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 1 note

up
0
btherl at yahoo dot com dot au
17 years ago
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.
To Top