Don't create transactions for SELECT queries
This commit is contained in:
parent
d169f9c331
commit
330aa32c97
1 changed files with 32 additions and 43 deletions
|
@ -136,11 +136,10 @@ class DBLayer {
|
||||||
$lastId = $this -> PDO -> lastInsertId();
|
$lastId = $this -> PDO -> lastInsertId();
|
||||||
$this -> PDO -> commit();
|
$this -> PDO -> commit();
|
||||||
}
|
}
|
||||||
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 new Exception( "error in inseting" );
|
throw $e; // new Exception( "error in inseting" );
|
||||||
}
|
}
|
||||||
return $lastId;
|
return $lastId;
|
||||||
}
|
}
|
||||||
|
@ -159,13 +158,10 @@ class DBLayer {
|
||||||
$this->useDb();
|
$this->useDb();
|
||||||
try {
|
try {
|
||||||
$sth = $this->PDO->prepare( "SELECT $param FROM $tb_name WHERE $where" );
|
$sth = $this->PDO->prepare( "SELECT $param 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 selection" );
|
||||||
throw new Exception( "error selection" );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $sth;
|
return $sth;
|
||||||
|
@ -184,14 +180,10 @@ class DBLayer {
|
||||||
$this->useDb();
|
$this->useDb();
|
||||||
try {
|
try {
|
||||||
$sth = $this->PDO->prepare("SELECT * FROM $tb_name WHERE $where");
|
$sth = $this->PDO->prepare("SELECT * FROM $tb_name WHERE $where");
|
||||||
$this -> PDO -> beginTransaction();
|
|
||||||
$sth->execute( $data );
|
$sth->execute( $data );
|
||||||
$this -> PDO -> commit();
|
|
||||||
}
|
}
|
||||||
catch( Exception $e )
|
catch (Exception $e) {
|
||||||
{
|
throw $e; // new Exception( "error selection" );
|
||||||
$this -> PDO -> rollBack();
|
|
||||||
throw new Exception( "error selection" );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $sth;
|
return $sth;
|
||||||
|
@ -208,26 +200,23 @@ class DBLayer {
|
||||||
public function update( $tb_name, $data, $where ) {
|
public function update( $tb_name, $data, $where ) {
|
||||||
$this->useDb();
|
$this->useDb();
|
||||||
$field_option_values = null;
|
$field_option_values = null;
|
||||||
foreach ( $data as $key => $value )
|
foreach ( $data as $key => $value ) {
|
||||||
{
|
|
||||||
$field_option_values .= ",$key" . '=:' . $key;
|
$field_option_values .= ",$key" . '=:' . $key;
|
||||||
}
|
}
|
||||||
$field_option_values = ltrim( $field_option_values, ',' );
|
$field_option_values = ltrim( $field_option_values, ',' );
|
||||||
try {
|
try {
|
||||||
$sth = $this -> PDO -> prepare( "UPDATE $tb_name SET $field_option_values WHERE $where " );
|
$sth = $this -> PDO -> prepare( "UPDATE $tb_name SET $field_option_values WHERE $where " );
|
||||||
|
|
||||||
foreach ( $data as $key => $value )
|
foreach ( $data as $key => $value ) {
|
||||||
{
|
|
||||||
$sth -> bindValue( ":$key", $value );
|
$sth -> bindValue( ":$key", $value );
|
||||||
}
|
}
|
||||||
$this -> PDO -> beginTransaction();
|
$this -> PDO -> beginTransaction();
|
||||||
$sth -> execute();
|
$sth -> execute();
|
||||||
$this -> PDO -> commit();
|
$this -> PDO -> commit();
|
||||||
}
|
}
|
||||||
catch ( Exception $e )
|
catch ( Exception $e ) {
|
||||||
{
|
|
||||||
$this->PDO->rollBack();
|
$this->PDO->rollBack();
|
||||||
throw new Exception( 'error in updating' );
|
throw $e; // new Exception( 'error in updating' );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -279,7 +268,7 @@ class DBLayer {
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
$this->PDO->rollBack();
|
$this->PDO->rollBack();
|
||||||
throw new Exception( "error in deleting" );
|
throw $e; // new Exception( "error in deleting" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue