Welcome Guest, Not a member yet? Register   Sign In
can't get db->transactions to work
#1

[eluser]atno[/eluser]
Hi,

Using the example from the user_guide i can't get the transactions to work. Here's the code and the results;

Model

Code:
class Register_m extends MY_Model {

      public function add_character() {
            $this->db->trans_start();

            $this->db->query("INSERT INTO keys(`userID`,`type`,`isActive`,`characterID`,`datetime`)
                  VALUES('$this->user_id','$this->type','1','$this->character_id','" . gmdate(time()) . "')");

            $this->db->query("INSERT INTO users
                  VALUES('$this->character_id','','0','','0')");
      
            $this->db->trans_complete();
            
            if ($this->db->trans_status() === FALSE) {
                  echo 'rollback';
            } else {
                  echo 'commit';
            }
      }

Result

Code:
A Database Error Occurred

Error Number: 1062

Duplicate entry '1' for key 'PRIMARY'

INSERT INTO keys(`userID`,`type`,`isActive`,`characterID`,`datetime`) VALUES('1','1234','1','1','223445','494949')

Filename: /Applications/MAMP/htdocs/staff/models/register_m.php

Line Number: 27

Why is the query executing and stopping the script instead of echoing 'rollback' ? I'm using mysql.




Theme © iAndrew 2016 - Forum software by © MyBB