Returns the current in-transaction status of the server

pg_transaction_status

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

pg_transaction_statusReturns the current in-transaction status of the server

說明

pg_transaction_status(PgSql\Connection $connection): int

Returns the current in-transaction status of the server.

警告

pg_transaction_status() will give incorrect results when using a PostgreSQL 7.3 server that has the parameter autocommit set to off. The server-side autocommit feature has been deprecated and does not exist in later server versions.

參數

connection

An PgSql\Connection instance.

返回值

The status can be PGSQL_TRANSACTION_IDLE (currently idle), PGSQL_TRANSACTION_ACTIVE (a command is in progress), PGSQL_TRANSACTION_INTRANS (idle, in a valid transaction block), or PGSQL_TRANSACTION_INERROR (idle, in a failed transaction block). PGSQL_TRANSACTION_UNKNOWN is reported if the connection is bad. PGSQL_TRANSACTION_ACTIVE is reported only when a query has been sent to the server and not yet completed.

更新日誌

版本 說明
8.1.0 現在 connection 參數接受 PgSql\Connection 實例,之前接受 資源(resource)

範例

示例 #1 pg_transaction_status() example

<?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';
  }    
?>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *