i have function in model supposed run 2 queries in transaction, update query not working.
public function delete($id = null) { if($id) { $delete = "delete borrowed_books id = '$id'; "; $mod="update `books` b inner join `borrowed_books` set b.nr_copies=b.nr_copies+1 b.id_book=a.id_book , a.id = '$id'; "; $this->db->trans_start(); $this->db->query($delete); $this->db->query($mod); $this->db->trans_complete(); if ($this->db->trans_status() === false) { return false; } else { return true; } } }
a quickfix might executing update before deleting;
public function delete($id = null) { if ($id) { $delete = "delete borrowed_books id = '$id'; "; $mod="update `books` b inner join `borrowed_books` set b.nr_copies=b.nr_copies+1 b.id_book=a.id_book , a.id = '$id'; "; $this->db->trans_start(); // execute update $this->db->query($mod); // delete $this->db->query($delete); $this->db->trans_complete(); if ($this->db->trans_status() === false) { return false; } else { return true; } } }
the update query condition; looking data not existent because deleted it. if update (then query finds result assuming condition correct), update..
Comments
Post a Comment