[eluser]Unknown[/eluser]
Hi there!
I wrote a Model with a create Method which looks like this:
Code:
public function new_device($data, $test_mode = FALSE)
{
$this->db->trans_start($test_mode);
$this->db->insert('table', $data);
$this->db->trans_complete();
return $this->db->trans_status();
}
I use the $test_mode var in my Controller; setting it to TRUE should validate the insert-Query without executing it.
Unfortunately, this method does always execute the query; setting $test_mode to TRUE has no Effect.
I even tried the following to be sure:
Code:
public function new_device($data, $test_mode = FALSE)
{
$this->db->trans_start(TRUE);
$this->db->insert('table', $data);
$this->db->trans_complete();
return $this->db->trans_status();
}
But this does also execute the Query and my DB-table grows...
I tried the following which
does work:
Code:
public function new_device($data, $test_mode = FALSE)
{
$this->db->trans_begin();
$this->db->insert('table', $data);
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
return FALSE;
}
else
{
if ( ! $test_mode)
{
$this->db->trans_commit();
}
else
{
$this->db->trans_rollback();
}
return TRUE;
}
}
Do you have any idea why the first two code-snippets don't work as expected? Is it because of the Active Record insert() Method?
Thanks in advance!