mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 17:46:18 +00:00
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
|
@ -135,13 +135,12 @@ class DBLayer {
|
|||
$sth -> execute();
|
||||
$lastId = $this -> PDO -> lastInsertId();
|
||||
$this -> PDO -> commit();
|
||||
}
|
||||
catch ( Exception $e )
|
||||
{
|
||||
}
|
||||
catch ( Exception $e ) {
|
||||
// for rolling back the changes during transaction
|
||||
$this -> PDO -> rollBack();
|
||||
throw new Exception( "error in inseting" );
|
||||
}
|
||||
// $this -> PDO -> rollBack();
|
||||
throw $e; // new Exception( "error in inseting" );
|
||||
}
|
||||
return $lastId;
|
||||
}
|
||||
|
||||
|
@ -158,14 +157,11 @@ class DBLayer {
|
|||
public function selectWithParameter( $param, $tb_name, $data, $where ) {
|
||||
$this->useDb();
|
||||
try {
|
||||
$sth = $this -> PDO -> prepare( "SELECT $param FROM $tb_name WHERE $where" );
|
||||
$this -> PDO -> beginTransaction();
|
||||
$sth -> execute( $data );
|
||||
$this -> PDO -> commit();
|
||||
$sth = $this->PDO->prepare( "SELECT $param FROM $tb_name WHERE $where" );
|
||||
$sth->execute( $data );
|
||||
}
|
||||
catch ( Exception $e ) {
|
||||
$this -> PDO -> rollBack();
|
||||
throw new Exception( "error selection" );
|
||||
throw $e; // new Exception( "error selection" );
|
||||
return false;
|
||||
}
|
||||
return $sth;
|
||||
|
@ -180,22 +176,18 @@ class DBLayer {
|
|||
* @param string $where where to select in format('fieldname=:fieldname' AND ...).
|
||||
* @return statement object.
|
||||
*/
|
||||
public function select( $tb_name, $data , $where ) {
|
||||
public function select($tb_name, $data , $where) {
|
||||
$this->useDb();
|
||||
try {
|
||||
$sth = $this -> PDO -> prepare( "SELECT * FROM $tb_name WHERE $where" );
|
||||
$this -> PDO -> beginTransaction();
|
||||
$sth -> execute( $data );
|
||||
$this -> PDO -> commit();
|
||||
}
|
||||
catch( Exception $e )
|
||||
{
|
||||
$this -> PDO -> rollBack();
|
||||
throw new Exception( "error selection" );
|
||||
return false;
|
||||
}
|
||||
return $sth;
|
||||
$sth = $this->PDO->prepare("SELECT * FROM $tb_name WHERE $where");
|
||||
$sth->execute( $data );
|
||||
}
|
||||
catch (Exception $e) {
|
||||
throw $e; // new Exception( "error selection" );
|
||||
return false;
|
||||
}
|
||||
return $sth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update function with prepared statement.
|
||||
|
@ -208,30 +200,27 @@ class DBLayer {
|
|||
public function update( $tb_name, $data, $where ) {
|
||||
$this->useDb();
|
||||
$field_option_values = null;
|
||||
foreach ( $data as $key => $value )
|
||||
{
|
||||
foreach ( $data as $key => $value ) {
|
||||
$field_option_values .= ",$key" . '=:' . $key;
|
||||
}
|
||||
}
|
||||
$field_option_values = ltrim( $field_option_values, ',' );
|
||||
try {
|
||||
$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 );
|
||||
}
|
||||
}
|
||||
$this -> PDO -> beginTransaction();
|
||||
$sth -> execute();
|
||||
$this -> PDO -> commit();
|
||||
}
|
||||
catch ( Exception $e )
|
||||
{
|
||||
$this -> PDO -> rollBack();
|
||||
throw new Exception( 'error in updating' );
|
||||
catch ( Exception $e ) {
|
||||
$this->PDO->rollBack();
|
||||
throw $e; // new Exception( 'error in updating' );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* insert function using prepared statements.
|
||||
|
@ -272,14 +261,14 @@ class DBLayer {
|
|||
public function delete( $tb_name, $data, $where ) {
|
||||
$this->useDb();
|
||||
try {
|
||||
$sth = $this -> PDO -> prepare( "DELETE FROM $tb_name WHERE $where" );
|
||||
$this -> PDO -> beginTransaction();
|
||||
$sth -> execute( $data );
|
||||
$this -> PDO -> commit();
|
||||
$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 new Exception( "error in deleting" );
|
||||
$this->PDO->rollBack();
|
||||
throw $e; // new Exception( "error in deleting" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue