[eluser]chubbypama[/eluser]
hi there. i'm just new to CI ... and i'm basing a mini application on some of the stuff i've learned from the CI tutorial.
i have written some code to write data from the URL into a database.
if the insert method fails, what's the best way to handle it?
for example, in my model, i have the following line of code to do my insert:
Code:
return $this->db->insert('clienthistory',$data);
what will be returned if the database gives some sort of error?
is there any best practices as far as handling errors are concerned? I've posted my code below. if you have any suggestions for improvement, i'm all ears.
thanks.
Controller:
Code:
public function saveClientXferStatus()
{
//if no client ip avail, don't bother.
if(isSet($_SERVER['REMOTE_ADDR']))
{
//NB: URI Class is initialized automatically by the system.
$val1=$this->uri->segment(0);
$val2=$this->uri->segment(1);
$val3=$this->uri->segment(2);
//validate the data
// If the values are not numeric there's nothing for us to do
if ( ! is_numeric($val1)) AND ( ! is_numeric($val2) ) AND ( ! is_numeric($val3) )
{
//write record to db.
$this->xferLogger_model->save_Client_History($val1,$val2,$val3);
$this->load->view('xferLogger/success');
}
}
}
code inside the model:
Code:
public function save_Client_History($val1, $val2, $val3)
{
$data = array(
'ip'=>$_SERVER['REMOTE_ADDR'],
'rtt'=> $val1,
'bt'=>$val2,
'ltcy'=> $val3
);
return $this->db->insert('clienthistory',$data);
}