Reduce unnecessary manual transaction commit

This commit is contained in:
kaetemi 2014-09-03 06:07:02 +02:00
parent 44b8223a5f
commit 27efa58777

View file

@ -127,8 +127,7 @@ class DBLayer {
$field_values = implode(',', array_merge(array(':' . implode(',:', array_keys($data))), array_values($datafunc))); $field_values = implode(',', array_merge(array(':' . implode(',:', array_keys($data))), array_values($datafunc)));
try { try {
$sth = $this -> PDO -> prepare( "INSERT INTO $tb_name ($field_options) VALUE ($field_values)" ); $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 ); $sth->bindValue( ":$key", $value );
} }
$this->PDO->beginTransaction(); $this->PDO->beginTransaction();
@ -138,7 +137,7 @@ class DBLayer {
} }
catch (Exception $e) { catch (Exception $e) {
// for rolling back the changes during transaction // for rolling back the changes during transaction
// $this -> PDO -> rollBack(); $this->PDO->rollBack();
throw $e; // new Exception( "error in inseting" ); throw $e; // new Exception( "error in inseting" );
} }
return $lastId; return $lastId;
@ -210,12 +209,9 @@ class DBLayer {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$sth->bindValue(":$key", $value); $sth->bindValue(":$key", $value);
} }
$this -> PDO -> beginTransaction();
$sth->execute(); $sth->execute();
$this -> PDO -> commit();
} }
catch (Exception $e) { catch (Exception $e) {
$this->PDO->rollBack();
throw $e; // new Exception( 'error in updating' ); throw $e; // new Exception( 'error in updating' );
return false; return false;
} }
@ -238,14 +234,9 @@ class DBLayer {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$sth->bindValue(":$key", $value); $sth->bindValue(":$key", $value);
} }
$this->PDO->beginTransaction();
// execution
$sth->execute(); $sth->execute();
$this->PDO->commit();
} }
catch (Exception $e) { catch (Exception $e) {
// for rolling back the changes during transaction
$this->PDO->rollBack();
throw $e; // new Exception("error in inserting"); throw $e; // new Exception("error in inserting");
} }
} }
@ -262,12 +253,9 @@ class DBLayer {
$this->useDb(); $this->useDb();
try { try {
$sth = $this->PDO->prepare("DELETE FROM $tb_name WHERE $where"); $sth = $this->PDO->prepare("DELETE FROM $tb_name WHERE $where");
$this->PDO->beginTransaction();
$sth->execute($data); $sth->execute($data);
$this->PDO->commit();
} }
catch (Exception $e) { catch (Exception $e) {
$this->PDO->rollBack();
throw $e; // new Exception( "error in deleting" ); throw $e; // new Exception( "error in deleting" );
} }
} }