Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • query roll back

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 437
    Answer it

    hey ci experts can you help me plz where im making mistake.... my query is not roll backed although im setting the first parameter in the $this->db->trans_start(TRUE); as TRUE the queries are only rollback when i remove the $this->db->trans_complete();

    here is my code

    $this->db->trans_start(TRUE); // Query will be rolled back $this->db->query('UPDATE tastybite.items SET name="cheeeeese" WHERE iditems="qw"'); for ($i=0; $i <10 ; $i++) { $this->db->query('INSERT INTO tastybite.product (name, price) VALUES ("product10", "122")');

    }

    $this->db->trans_complete();

 2 Answer(s)

  • HI

    I think, you are testing Transaction by executing all queries in a correct format.

    Please make any one query field wrong and then test, it will work. When you are removing $this->db->trans_complete(); it means that transaction has started and all queries are executed successfully, but as we know to see the saved data $this->db->trans_complete(); is must to commit all those queries.

    If you want to check rollback is working correctly or not, make any field wrong in any loop index Like change name to namee and then check, it will really rollback.

    Note:- Please check Database Engine, it should be InnoDB to implement Transaction

    Regards
    Deepak

  • The code itself seems to be correct. However, one possible explanation to your problem is the type of storage engine your table is using.

    MySQL do not support transactions for MyISAM engine. So if your table is using MyISAM, there is nothing codeIgniter could do. Check the storage engine your table is using. If it is MyISAM, change it to InnoDB.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: