So I have two methods. Method one adds a row to my database. Method two selects and updates the latest 10 rows of the table.
If method one adds a new row after method two selects the data but before it updates it will method two update the wrong 10 rows? Will transactions help here or do i need to lock tables?
function one(){
insert row
}
function two(){
select latest 10 rows
update latest 10 rows
}
// EDIT /////////////////////////////////////////////////////////////////////////////
I was reluctant to throw in my actual methods (they are codeIgniter methods) but here they are
function one(){
insert row
}
function two(){
$this->db->where('status', '1');
$this->db->limit(10);
$query = $this->db->get('rrsf_users');
$this->db->where('status', '1');
$this->db->limit(10);
$this->db->update('rrsf_users', array('status' => '2'));
}
So it looks like two separate queries hence the "current last 10 rows" problem. Not sure the best fix for this. Lock tables or cycle though each index selected from the query and add this to the where query?