CodeIgniter Forums
Transactions. Which query failed? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Transactions. Which query failed? (/showthread.php?tid=25955)



Transactions. Which query failed? - El Forum - 01-01-2010

[eluser]srisa[/eluser]
Hello,

I plan to use transactions with db_debug turned off.
Code:
$this->db->trans_start();
$this->db->query('query1');
$this->db->query('query2');
$this->db->query('query3');
$this->db->trans_complete();
Assuming that one of the three queries have failed, is there anyway to know which query failed and what the error message was?

I tested it out with 3 queries, where queries 1 and 3 succeed and query 2 fails. I tried to get hold of the query with following code but it is returning the last query , query 3 (which succeeds if executed)
Code:
if ($this->db->trans_status() === FALSE)
{
    echo 'Query that failed was '.$this->db->last_query().'<br />';
    # above line is returning query 3
}
So, is there a way to get hold of the query that failed using the transactions in the above mentioned manner?

Thank you.