CodeIgniter Forums
How does $this->db->trans_status() work? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How does $this->db->trans_status() work? (/thread-52925.html)



How does $this->db->trans_status() work? - El Forum - 07-02-2012

[eluser]Syed Rakib Al Hasan[/eluser]
How exactly does `$this->db->trans_status()` understand that whether the queries in the transaction were successful or not?

Source: http://ellislab.com/codeigniter/user-guide/database/transactions.html
Quote:
Code:
$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();
}



How does $this->db->trans_status() work? - El Forum - 07-02-2012

[eluser]WanWizard[/eluser]
It's status is set to FALSE if a query fails, so if running a query returns FALSE.


How does $this->db->trans_status() work? - El Forum - 07-02-2012

[eluser]Syed Rakib Al Hasan[/eluser]
[quote author="WanWizard" date="1341261683"]It's status is set to FALSE if a query fails, so if running a query returns FALSE.[/quote]
Thanks. I am interested to know HOW does dba->get_status() understand that it, in fact, is returning the correct status of the SQL? Is it based on SQL deadlock issues? Is it based on malformed SQL strings? Is it based on timeout issues? I actually have about 10 to 15 SQLs between a trans_start and trans_complete


How does $this->db->trans_status() work? - El Forum - 07-02-2012

[eluser]WanWizard[/eluser]
It's based on the return value of whatever function is used to run the query (which depends on the driver used).
So basically on any error that causes the query not to complete succesfully.