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.
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';
}
?>
btherl at yahoo dot com dot au ¶
6 years ago
hofman dot tomas at gmail dot com ¶
2 years ago
Exact values of constants:
PGSQL_TRANSACTION_IDLE = 0
PGSQL_TRANSACTION_ACTIVE = 1
PGSQL_TRANSACTION_INTRANS = 2
PGSQL_TRANSACTION_INERROR = 3
PGSQL_TRANSACTION_UNKNOWN = 4
