bcit-ci / CodeIgniter

Open Source PHP Framework (originally from EllisLab)

Home Page:https://codeigniter.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transactions snippets on user guide are misleading

bunglegrind opened this issue · comments

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