CodeIgniter Forums

Full Version: How does $this->db->trans_status() work?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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-gui...tions.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();
}

El Forum

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

El Forum

[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

El Forum

[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.