Welcome Guest, Not a member yet? Register   Sign In
pdo db driver and transactions CI 2.1 - bug?
#1

[eluser]neilmcgann[/eluser]
Hi Folks - first post :-)

I have been using the mysql pdo driver with no problems until I have tried to use transactions. Simply described, a failed transaction does not roll back all the statements.

If I switch the db config driver type to mysqli it works with no problem and rolls back perfectly.

This is a stripped down version of the code - it basically just deletes some stuff and then adds some new stuff, all wrapped in a transaction.

Code:
$this->CI->db->trans_start();

$this->CI->db->where('group_id',$group);
$this->CI->db->delete('users_groups_perms'); //delete a load of stuff to be replaced

$this->CI->db->insert_batch('users_groups_perms', $data); //deliberate error in $data to check rollback
  
$this->CI->db->trans_complete();

//do some stuff with $this->CI->db->trans_status()

I'm provoking a deliberate fail in the insert to check the rollback works - which it does in mysqli, but not in pdo. I've tried using trans_begin and manually doing the rollback/commit, but this doesn't work either. The trans_status function detects the error, so the driver knows something has gone wrong...but no rollback.

Anyone seen anything like this before?

Neil
#2

[eluser]Unknown[/eluser]
In the constructor of pdo_driver
Code:
$this->trans_enabled = FALSE;
this is why transactions can't start.

should be
Code:
$this->trans_enabled = TRUE;
or if it is removed, should be better.


Also in "trans_commit" method of pdo_driver
Code:
$ret = $this->conn->commit();

should be
Code:
$ret = $this->conn_id->commit();


These are the bugs i guess.




Theme © iAndrew 2016 - Forum software by © MyBB