This topic is locked
[SOLVED]

 Using transaction control

1/14/2018 7:22:52 AM
PHPRunner General questions
G
gbhmayer1 author

I'm inserting a button that will perform a series of queries on the database (MySQL). I would like to know if I can use transaction control as the example or if there is another way to use it:
try {

$db->beginTransaction();
$db->query('query 1');

$db->query('query 2');

$db->query('query 3');
$db->commit();

} catch (Exception $e) {

$db->rollback();

}

G
gbhmayer1 author 1/14/2018

Apparently this worked:
global $cman;
try{

$sql = "INSERT INTO myTable VALUES('value1','value2')";
$connection = $cman->byName("myConn");

$connection->EXEC("START TRANSACTION;");

$connection->exec($sql);

$connection->EXEC("COMMIT;");

}catch (Exception $e) {

$connection->EXEC("ROLLBACK;");

}