Welcome Guest, Not a member yet? Register   Sign In
¿Active Record Auto Commit?
#1

[eluser]reset[/eluser]
Hello everyone,

Before I had my Mysql database with MyISAM tables, and wore Active Record ... Moved by all InnoDB tables, and everything continues to operate exactly alike, inserts, updates..., and I have not changed anything in the code part of my Codeigniter models. My question is if Active Record auto commit transactions, or why is it happening?
#2

[eluser]Michael Wales[/eluser]
Not sure on the question... I think: You are trying to use transactions, so you changed your table type, but Active Record is still attempting to commit the query, without using the transaction process?

Can you post some code so we know what you have attempted?
#3

[eluser]reset[/eluser]
Hi Michael Wales,

I have this funtion that don't do commit and runs ok under Innondb.

Code:
public function insert_practica($data){
    $this->db->insert($this->tablas['practicas'],$data);
}

Thanks
#4

[eluser]Michael Wales[/eluser]
Quote:I have this funtion that don’t do commit and runs ok under Innondb.

So you are saying this function does work with an InnoDB table but does not with MyISAM?
#5

[eluser]reset[/eluser]
No, I say that this function works with both, but for InnoDB, should not commit?

For example, for InnoDB, must be like that?
Code:
public function insert_practica($data){
    $this->db->trans_begin();
    $this->db->insert($this->tablas['practicas'],$data);
    if ($this->db->trans_status() === FALSE){
        $this->db->trans_rollback();
    } else {
        $this->db->trans_commit();
    }
}

PD: Sorry for my english Tongue
#6

[eluser]Michael Wales[/eluser]
Yes - you must tell CodeIgniter to use the transaction functionality, it won't just do so by default. The code example you used would work fine.

Without doing so your queries will be executed automatically.
#7

[eluser]Chris Newton[/eluser]
You can also run multiple queries within a transaction.
Code:
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
$this->db->trans_complete();
#8

[eluser]reset[/eluser]
I saw the user_guide before question, thanks, I would like to know if I can use innodb without transations, only for Foreing Key, or if is necesary to use transations.

Michael, when you say
Quote:"Without doing so your queries will be executed automatically."
You want to say that if I do an insert, Active Record commit the transation automatically in a innodb table, or I can do an insert without transations with an innondb table? That my question.

Sorry for my english
#9

[eluser]Michael Wales[/eluser]
Regardless of the table type, doesn't matter - Active Record methods will automatically do what you tell them to - or at least try to.

Code:
// This will immediately attempt to insert a row and return TRUE/FALSE based on success
$this->db->insert('users', array('email'=>$email));

Quote:If I do an insert, Active Record commit the transation automatically in a innodb table
If you do an insert, there is no transaction. Transactions only occur when you explicitly request them.

Quote:I can do an insert without transations with an innondb table?
Yes - you can do it with any table type.
#10

[eluser]reset[/eluser]
Thanks Michael Smile




Theme © iAndrew 2016 - Forum software by © MyBB