Saturday, December 9, 2017

PDO Transaction syntax with try catch

PDO Transaction syntax with try catch


if ($dbh->beginTransaction()) 
{
  try 
  {
    //your db code
    $dbh->commit();
  } 
  catch (Exception $ex) 
  {
    if ($dbh->inTransaction())
    {
       $dbh->rollBack();
    }        
  }
}

Reference:

https://stackoverflow.com/questions/24408434/pdo-transaction-syntax-with-try-catch

No comments: