1--TEST-- 2PDO PgSQL isInTransaction 3--SKIPIF-- 4<?php 5if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); 6require __DIR__ . '/config.inc'; 7require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 8PDOTest::skip(); 9?> 10--FILE-- 11<?php 12require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 13$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 15$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); 16 17$db->exec('CREATE TABLE test (a integer not null primary key, b text)'); 18 19$db->beginTransaction(); 20try { 21echo "Test PDO::PGSQL_TRANSACTION_INTRANS\n"; 22var_dump($db->inTransaction()); 23 24$stmt = $db->prepare("INSERT INTO test (a, b) values (?, ?)"); 25$stmt->bindValue(1, 1); 26$stmt->bindValue(2, "test insert"); 27$stmt->execute(); 28 29$db->commit(); 30 31echo "Test PDO::PGSQL_TRANSACTION_IDLE\n"; 32var_dump($db->inTransaction()); 33 34$db->beginTransaction(); 35 36try { 37$stmt = $db->prepare("INSERT INTO test (a, b) values (?, ?)"); 38$stmt->bindValue(1, "error"); 39$stmt->bindValue(2, "test insert"); 40$stmt->execute(); 41} catch (Exception $e) { 42 /* We catch the exception because the execute will give error and we must test the PDO::PGSQL_TRANSACTION_ERROR */ 43 echo "Test PDO::PGSQL_TRANSACTION_INERROR\n"; 44 var_dump($db->inTransaction()); 45 $db->rollBack(); 46} 47 48echo "Test PDO::PGSQL_TRANSACTION_IDLE\n"; 49var_dump($db->inTransaction()); 50 51} catch (Exception $e) { 52 /* catch exceptions so that we can show the relative error */ 53 echo "Exception! at line ", $e->getLine(), "\n"; 54 var_dump($e->getMessage()); 55} 56 57?> 58--EXPECT-- 59Test PDO::PGSQL_TRANSACTION_INTRANS 60bool(true) 61Test PDO::PGSQL_TRANSACTION_IDLE 62bool(false) 63Test PDO::PGSQL_TRANSACTION_INERROR 64bool(true) 65Test PDO::PGSQL_TRANSACTION_IDLE 66bool(false) 67