Forums: [SOLVED] Using transaction control - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[SOLVED] Using transaction control Rate Topic: -----

#1 User is offline   Gersonbhm 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 47
  • Joined: 28-May 08

Posted 14 January 2018 - 12:22 PM

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();
}
0

#2 User is offline   Gersonbhm 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 47
  • Joined: 28-May 08

Posted 14 January 2018 - 01:50 PM

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;");
}
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked