CodeIgniter Forums
Error Handling while using $this->db->insert - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Error Handling while using $this->db->insert (/thread-49338.html)



Error Handling while using $this->db->insert - El Forum - 02-16-2012

[eluser]Unknown[/eluser]
<?php
class imrtrackerModel extends CI_Model {

private $imrmain= 'imrmain';

function imrtracker(){
parent::__construct();
}

function save($imrtracker){
try
{
$rc_save = $this->db->insert($this->imrmain, $imrtracker);
echo 'outside error';
if (! $rc_save)
{
throw new Exception();
}
}

catch (Exception $e)
{
echo 'exception';
}

}

}
?>

The above is my model code. I want to capture the duplicate entries. But i am not able to handle the error. Kindly help me. Am new to Codeigniter.


Error Handling while using $this->db->insert - El Forum - 02-16-2012

[eluser]InsiteFX[/eluser]
CodeIgniter User Guide - Query Helper Functions



Error Handling while using $this->db->insert - El Forum - 02-16-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
You dont need to catch exceptions.
If you need to check duplicate entries, run your sql command to get duplicate entries.