Welcome Guest, Not a member yet? Register   Sign In
transaction doesn't work properly
#1

(This post was last modified: 09-24-2017, 07:03 AM by vahid.vdn.)

I'm looking for a case how `transaction` do it's job. In first case I write a `sleep(10000)` between two queries, then turn of the wamp server:

PHP Code:
$this->db->trans_begin();
$q1 $this->db->query("INSERT INTO `test`(`test_col`) VALUES ('aaaaaa')");
sleep(100000);
$q2 $this->db->query("INSERT INTO `test`(`test_col`) VALUES ('bbbbbb')");
$this->db->trans_complete(); 


But first record is saved without second one. Then I tried with another case, that first query fails because of duplicated value:

PHP Code:
$this->db->trans_begin();
$q1 $this->db->query("INSERT INTO `test`(`test_col`) VALUES ('duplicated')");
$q2 $this->db->query("INSERT INTO `test`(`test_col`) VALUES ('new row')");
$this->db->trans_complete(); 



But again the new one exist in the database. Any idea? Is there anything I'm missing?


Also `trans_rollback`  doesn't work.

PHP Code:
if ($this->db->trans_status() === FALSE)
{
 
   // I get this line, but trans_rollback doesn't work
 
   $this->db->trans_rollback();

Reply


Messages In This Thread
transaction doesn't work properly - by vahid.vdn - 09-24-2017, 07:02 AM
RE: transaction doesn't work properly - by Narf - 09-25-2017, 02:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB