merge pdo_commit and pdo_rollback and renamed to pdo_transaction.phpt

This commit is contained in:
v-kaywon 2017-04-13 09:33:44 -07:00
parent 733ac45497
commit 0d4a2573d4
2 changed files with 18 additions and 43 deletions

View file

@ -1,38 +0,0 @@
--TEST--
starts a transaction, delete rows and commit the transaction
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = new PDO( "sqlsrv:Server=$serverName; Database = tempdb ", $username, $password);
$conn->exec("IF OBJECT_ID('Table1', 'U') IS NOT NULL DROP TABLE Table1");
$conn->exec("CREATE TABLE Table1(col1 CHARACTER(1), col2 CHARACTER(1)) ");
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'b') ");
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'c') ");
//revert the inserts
$conn->beginTransaction();
$rows = $conn->exec("delete from Table1 where col1 = 'a'");
$conn->commit();
echo $rows." rows affected\n";
$stmt = $conn->query("select * from Table1");
if ( count( $stmt->fetchAll() ) == 0 )
echo "Transaction committed successfully\n";
else
echo "Transaction failed to commit\n";
//drop the created temp table
$conn->exec("DROP TABLE Table1 ");
//free statement and connection
$stmt = NULL;
$conn = NULL;
?>
--EXPECT--
2 rows affected
Transaction committed successfully

View file

@ -14,9 +14,9 @@ starts a transaction, delete rows and rollback the transaction
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'b') ");
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'c') ");
//revert the inserts
//revert the inserts but roll back
$conn->beginTransaction();
$ret = $conn->exec("delete from Table1 where col1 = 'a'");
$rows = $conn->exec("delete from Table1 where col1 = 'a'");
$conn->rollback();
$stmt = $conn->query("SELECT * FROM Table1");
@ -25,14 +25,27 @@ starts a transaction, delete rows and rollback the transaction
echo "Transaction rolled back successfully\n";
else
echo "Transaction failed to roll back\n";
//revert the inserts then commit
$conn->beginTransaction();
$rows = $conn->exec("delete from Table1 where col1 = 'a'");
$conn->commit();
echo $rows." rows affected\n";
$stmt = $conn->query("select * from Table1");
if ( count( $stmt->fetchAll() ) == 0 )
echo "Transaction committed successfully\n";
else
echo "Transaction failed to commit\n";
//drop the created temp table
$conn->exec("DROP TABLE Table1 ");
//free statement and connection
$ret=NULL;
$stmt = NULL;
$conn=NULL;
$conn = NULL;
?>
--EXPECT--
Transaction rolled back successfully
Transaction rolled back successfully
2 rows affected
Transaction committed successfully