Welcome Guest, Not a member yet? Register   Sign In
using transaction for database
#1

[eluser]rana[/eluser]
I am trying to using transaction feature of codeigniter.

Code:
$this->db->trans_start();
            
        if($id != "") //exist record, update
        {        
            $where = "model_id='".$id."'";
            $sql = $this->db->update_string($this->table, $model, $where);
            $result = $this->db->query($sql);        
        }
        else//insert data
        {
            $this->db->select_max('model_id', 'model_id');
            $result = $this->db->get($this->table);
            $row = $result->row_array();
            $model["model_id"] = $row["model_id"] + 1;
            $user["user_id"] = $row["model_id"] + 1;
            $this->db->insert($this->table,$model);
            
            $data["gallery_id"]=$gallery_id;
            $data["model_id"]= $model["model_id"];
            $this->db->insert("tbl_gallery_model",$data);        
        }        
        
        
        $this->db->where("id",$id);
        $this->db->update('tbl_user',$user);
        if($this->db->affected_rows() <= 0)        
        {
            $user["id"]=$id;
            $this->db->insert('tbl_user',$user);
        }    
        
        $this->db->trans_complete();

But, transaction isn't working. Data is inserting to one table, not to another, while it shouldn't insert to anyone....
#2

[eluser]Dam1an[/eluser]
What database engine are you using, as transations aren't supported by all engines, such as the default MySQL MyISAM (I think you need InnoDB, although feel free to correct me if I'm wrong)
#3

[eluser]rana[/eluser]
i didn't find innodb at xampp's phpmyadmin. can u give me a suggesion??

Regards
#4

[eluser]rana[/eluser]
Ok, I found it. Thanks
#5

[eluser]Dam1an[/eluser]
I know you can specify the engine to use when using the SQL query tab
If you're too lazy to write it out yourself, create it as normal, copy the generated code and recreate the table with the differant engine

(I would look if it's possible ina slsightly more elegant manor, but don't have xampp on ym work PC)
#6

[eluser]Dregond Rahl[/eluser]
When phpMyAdmin loads on the main you should see "Storage Engine" in the list. Click it and when it loads see if you have this.

"InnoDB | Supports transactions, row-level locking, and foreign keys"

EDIT: hahah XD




Theme © iAndrew 2016 - Forum software by © MyBB