CodeIgniter Forums

Full Version: Error Handling while using $this->db->insert
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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.

El Forum

El Forum

[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.