CodeIgniter Forums
query helper methods and transactions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: Issues (https://forum.codeigniter.com/forum-19.html)
+--- Thread: query helper methods and transactions (/thread-1451.html)



query helper methods and transactions - quasiperfect - 03-11-2015

hi

the query helper methods insert_id and affected_rows return 0 after a transaction that contains a update and insert

i mention that the transaction is successful because it inserts the data without any problems

is this a bug or i'm missing something ?

my code is like this

PHP Code:
$this->db->trans_start();
$this->db->query('update query here');
$this->db->query('insert query here');
$this->db->trans_complete();

if (
$this->db->trans_status() !== FALSE)
{
    echo $this->db->insert_id();
 
   echo $this->db->affected_rows();




RE: query helper methods and transactions - Nichiren - 03-11-2015

I haven't tested this myself but have you tried running insert_id() and affected_rows() before calling trans_complete()? I'd imagine that once trans_complete() is called, insert_id() and affected_rows() would no longer be tied to the queries run from within the transaction.


RE: query helper methods and transactions - Narf - 03-11-2015

(03-11-2015, 11:57 AM)Nichiren Wrote: I haven't tested this myself but have you tried running insert_id() and affected_rows() before calling trans_complete()? I'd imagine that once trans_complete() is called, insert_id() and affected_rows() would no longer be tied to the queries run from within the transaction.

Yep, that's the most probable cause ... This happens either at the SQL level, or the PHP-extension one - CI has no control over it.


RE: query helper methods and transactions - quasiperfect - 03-12-2015

yes you are right i retested and if you run the functions before trans_complete() is all working