Reduce unnecessary manual transaction commit
This commit is contained in:
parent
44b8223a5f
commit
27efa58777
1 changed files with 23 additions and 35 deletions
|
@ -127,8 +127,7 @@ class DBLayer {
|
|||
$field_values = implode(',', array_merge(array(':' . implode(',:', array_keys($data))), array_values($datafunc)));
|
||||
try {
|
||||
$sth = $this -> PDO -> prepare( "INSERT INTO $tb_name ($field_options) VALUE ($field_values)" );
|
||||
foreach ( $data as $key => $value )
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$sth->bindValue( ":$key", $value );
|
||||
}
|
||||
$this->PDO->beginTransaction();
|
||||
|
@ -138,7 +137,7 @@ class DBLayer {
|
|||
}
|
||||
catch (Exception $e) {
|
||||
// for rolling back the changes during transaction
|
||||
// $this -> PDO -> rollBack();
|
||||
$this->PDO->rollBack();
|
||||
throw $e; // new Exception( "error in inseting" );
|
||||
}
|
||||
return $lastId;
|
||||
|
@ -210,12 +209,9 @@ class DBLayer {
|
|||
foreach ($data as $key => $value) {
|
||||
$sth->bindValue(":$key", $value);
|
||||
}
|
||||
$this -> PDO -> beginTransaction();
|
||||
$sth->execute();
|
||||
$this -> PDO -> commit();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->PDO->rollBack();
|
||||
throw $e; // new Exception( 'error in updating' );
|
||||
return false;
|
||||
}
|
||||
|
@ -238,14 +234,9 @@ class DBLayer {
|
|||
foreach ($data as $key => $value) {
|
||||
$sth->bindValue(":$key", $value);
|
||||
}
|
||||
$this->PDO->beginTransaction();
|
||||
// execution
|
||||
$sth->execute();
|
||||
$this->PDO->commit();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// for rolling back the changes during transaction
|
||||
$this->PDO->rollBack();
|
||||
throw $e; // new Exception("error in inserting");
|
||||
}
|
||||
}
|
||||
|
@ -262,12 +253,9 @@ class DBLayer {
|
|||
$this->useDb();
|
||||
try {
|
||||
$sth = $this->PDO->prepare("DELETE FROM $tb_name WHERE $where");
|
||||
$this->PDO->beginTransaction();
|
||||
$sth->execute($data);
|
||||
$this->PDO->commit();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->PDO->rollBack();
|
||||
throw $e; // new Exception( "error in deleting" );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue