Login   Register  
PHP Classes
elePHPant
Icontem

Transactions doesn't work correctly

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PDO Multi Connection Class  >  All threads  >  Transactions doesn't work correctly  >  (Un) Subscribe thread alerts  
Subject:Transactions doesn't work correctly
Summary:Transactions doesn't makes rollback
Messages:2
Author:Marco Rossi
Date:2013-01-21 15:52:05
Update:2013-01-21 16:47:35
 

  1. Transactions doesn't work correctly   Reply   Report abuse  
Picture of Marco Rossi
Marco Rossi
2013-01-21 15:52:05
Hi!!!
I'm trying to make a rollback after a query, but doesn't work...

if i execute this

$db_pdo->transaction("B");
for($i=0;$i<20000;$i++){
$db_pdo->query("INSERT INTO test_insert (name) VALUES ('Gino');");
}
$db_pdo->transaction("R");

it commits the query without rollback...
How can i fix it?

  2. Re: Transactions doesn't work correctly   Reply   Report abuse  
Picture of Marco Rossi
Marco Rossi
2013-01-21 16:47:35 - In reply to message 1 from Marco Rossi
i made this modify in the class:
($this->con->query("SET ISOLATION TO SERIALIZABLE");)

public function transaction($type){
$this->err_msg = "";
if($this->con!=null){
try{
if($type=="B"){
$this->con->query("SET ISOLATION TO SERIALIZABLE");
$this->con->beginTransaction();
}
elseif($type=="C")
$this->con->commit();
elseif($type=="R")
$this->con->rollBack();
else{
$this->err_msg = "Error: The passed param is wrong! just allow [B=begin, C=commit or R=rollback]";
return false;
}
}catch(PDOException $e){
$this->err_msg = "Error: ". $e->getMessage();
return false;
}
}else{
$this->err_msg = "Error: Connection to database lost.";
return false;
}
}