Exemplo n.º 1
0
//======================================================
include "{$test_dir}/auto_commit.inc.php";
//***********************************************************************
// Prepared Insert Query with Transactions
//***********************************************************************
print_header('Prepared Insert Query with Transaction');
// No Data with IDs of 10 or 11
$strsql = 'select * from contacts where id IN (?, ?)';
$strsql0 = 'select * from contacts where id IN (10, 11)';
$param1 = 10;
$param2 = 11;
$data1->prepare($strsql, array(&$param1, &$param2));
$data1->execute();
print_array($data1->data_key_assoc('id'));
// Turn off auto commit
$data1->auto_commit(false);
// Insert two test Rows
$strsql2 = 'insert into contacts (id, first_name, last_name, city, state) values (?, ?, ?, ?, ?)';
$params = array(10, 'bob', 'bobson', 'toowalk', 'MN');
$data1->prepare($strsql2);
$data1->execute($params);
$params = array(11, 'john', 'smith', 'Racine', 'WI');
$data1->prepare($strsql2);
$data1->execute($params);
$data1->commit();
print_sub_header('Inserted two rows and committed. They should exist...');
$data1->prepare($strsql);
$data1->execute(array(&$param1, &$param2));
$data = $data1->data_key_assoc('id');
print_array($data);
print_sub_header('Deleted the two rows that were added then rolled back.');