• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
transaction doesn't work properly

#1
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

#2
I must use InnoDB in order to work with transactions!
Reply

#3
The problem is that since you are using trans_begin instead of trans_start, you are running the transaction manually. When running transactions manually, you don't want to use trans_complete, but you are. Remove trans_complete, and then you should be able to rollback or commit.
Reply

#4
(09-24-2017, 09:24 AM)skunkbad Wrote: The problem is that since you are using trans_begin instead of trans_start, you are running the transaction manually. When running transactions manually, you don't want to use trans_complete, but you are. Remove trans_complete, and then you should be able to rollback or commit.

I don't want to use rollback or commit. In my case, the problem was with Storage Engine. It must be InnoDB.
Reply

#5
MyISAM strikes again.
Reply

#6
LOL! @Narf
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#7
(09-25-2017, 01:48 AM)vahid.vdn Wrote:
(09-24-2017, 09:24 AM)skunkbad Wrote: The problem is that since you are using trans_begin instead of trans_start, you are running the transaction manually. When running transactions manually, you don't want to use trans_complete, but you are. Remove trans_complete, and then you should be able to rollback or commit.

I don't want to use rollback or commit. In my case, the problem was with Storage Engine. It must be InnoDB.

If you don't want to rollback or commit, then why are you using trans_begin instead of trans_start? You need to go back and read the docs related to transactions.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.