bcit-ci / CodeIgniter

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
18.27k stars 7.6k forks source link

Transactions snippets on user guide are misleading #6191

Open bunglegrind opened 1 year ago

bunglegrind commented 1 year ago

https://codeigniter.com/userguide3/database/transactions.html?highlight=transactions#running-transactions-manually

$this->db->trans_begin();

$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');

if ($this->db->trans_status() === FALSE)
{
        $this->db->trans_rollback();
}
else
{
        $this->db->trans_commit();
}

Well, trans_commit can fail (and it does!). The return value (which is actually a boolean) must be checked to ensure the correcteness of the transaction. Same applies to trans_complete