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