Lost update is a common MySQL issue and to solve it the select query should be edited to be a select for update query like this
select * from users where id = 1 FOR UPDATE
to prevent other users from working on the same row at the same time. I want to do this in codeigniter by editing this query to be a select for update query
public function get_row_data($id)
{
$this->db->where('id',$id);
$result = $this->db->get('users');
if($result && $result->num_rows() > 0)
{
return $result->row();
}
else
{
return false;
}
}
I can use the above simple query but prefer if the model query could be converted.
Thanks
It Seems You want to acquire Row Level Locking in Mysql and codeigniter query builder doesn't allow to manipulate its method to produce custom sql query
$this->db->trans_begin();
$this->db->query('you query goes here');
// other task .....
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
} else {
$this->db->trans_commit();
}