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