PostgreSQL 函数
在线手册:中文 英文
PHP手册

pg_transaction_status

(PHP 5 >= 5.1.0)

pg_transaction_statusReturns the current in-transaction status of the server.

说明

int pg_transaction_status ( resource $connection )

Returns the current in-transaction status of the server.

Caution

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

PostgreSQL database connection resource.

返回值

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.

范例

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


PostgreSQL 函数
在线手册:中文 英文
PHP手册
PHP手册 - N: Returns the current in-transaction status of the server.

用户评论:

hofman dot tomas at gmail dot com (08-Jul-2010 09: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 (18-Jul-2006 03: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.