Query eror handling in CodeIgniter
Posted
by
Sajith S Narayanan
on Stack Overflow
See other posts from Stack Overflow
or by Sajith S Narayanan
Published on 2011-01-13T02:51:19Z
Indexed on
2011/01/13
2:53 UTC
Read the original article
Hit count: 387
codeigniter
|activerecord
Hi All,
I am trying to execute an MySql query using the CI Active methods. If the query is malformed, then CI invokes internal server error 500 and quits without processing the next steps..
I need to roll back all the other queries processed before that error statement, and the roll back is also not happening.. can you help pls.
The code snippets is as below:
function dbInsertInformationToDB($data_array) { $returnID = ""; $uniqueDataArray = array();
// I prepare a array of values here
$uniqueTableList = filter_unique_tables($data_array[2]);
$this->db->trans_begin();
// inserting is done here
// when there is a query error in $this->db->insert().. it is not rolling back the previous query executed
foreach($uniqueTableList as $table_name)
{
$uniqueDataArray = filterDataArray($data_array,$table_name,2);
$this->db->insert($table_name,$uniqueDataArray);
if ($this->db->_error_message())
{
$error = "I am caught!!";
}
$returnID = $this->db->affected_rows();
}
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
return "ERROR";
}
© Stack Overflow or respective owner