1--TEST-- 2PDO Common: transactions 3--EXTENSIONS-- 4pdo 5--SKIPIF-- 6<?php 7$dir = getenv('REDIR_TEST_DIR'); 8if (false == $dir) die('skip no driver'); 9require_once $dir . 'pdo_test.inc'; 10PDOTest::skip(); 11 12$db = PDOTest::factory(); 13try { 14 $db->beginTransaction(); 15 $db->rollback(); 16} catch (PDOException $e) { 17 die('skip no working transactions: ' . $e->getMessage()); 18} 19 20if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { 21 require_once(__DIR__ . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/inc/mysql_pdo_test.inc'); 22 if (false === MySQLPDOTest::detect_transactional_mysql_engine($db)) { 23 die('skip your mysql configuration does not support working transactions'); 24 } 25} 26?> 27--FILE-- 28<?php 29if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); 30require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 31$db = PDOTest::factory(); 32 33if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { 34 require_once(__DIR__ . DIRECTORY_SEPARATOR . '../../pdo_mysql/tests/inc/mysql_pdo_test.inc'); 35 $suf = ' ENGINE=' . MySQLPDOTest::detect_transactional_mysql_engine($db); 36} else { 37 $suf = ''; 38} 39 40$db->exec('CREATE TABLE test017(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))'.$suf); 41$db->exec("INSERT INTO test017 VALUES(1, 'A')"); 42$db->exec("INSERT INTO test017 VALUES(2, 'B')"); 43$db->exec("INSERT INTO test017 VALUES(3, 'C')"); 44$delete = $db->prepare('DELETE FROM test017'); 45 46function countRows($action) { 47 global $db; 48 $select = $db->prepare('SELECT COUNT(*) FROM test017'); 49 $select->execute(); 50 $res = $select->fetchColumn(); 51 return "Counted $res rows after $action.\n"; 52} 53 54echo countRows('insert'); 55 56$db->beginTransaction(); 57$delete->execute(); 58echo countRows('delete'); 59$db->rollBack(); 60 61echo countRows('rollback'); 62 63$db->beginTransaction(); 64$delete->execute(); 65echo countRows('delete'); 66$db->commit(); 67 68echo countRows('commit'); 69?> 70--CLEAN-- 71<?php 72require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 73$db = PDOTest::factory(); 74PDOTest::dropTableIfExists($db, "test017"); 75?> 76--EXPECT-- 77Counted 3 rows after insert. 78Counted 0 rows after delete. 79Counted 3 rows after rollback. 80Counted 0 rows after delete. 81Counted 0 rows after commit. 82