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....


Messages In This Thread
using transaction for database - by El Forum - 06-22-2009, 01:54 AM
using transaction for database - by El Forum - 06-22-2009, 01:57 AM
using transaction for database - by El Forum - 06-22-2009, 02:10 AM
using transaction for database - by El Forum - 06-22-2009, 02:17 AM
using transaction for database - by El Forum - 06-22-2009, 02:22 AM
using transaction for database - by El Forum - 06-22-2009, 02:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB