title: codeigniter database error handling
body: <p>Controller:</p>
  
  <pre><code>function edit($id)
  {
      $this-&gt;form_validation-&gt;set_rules('name', 'Name', 'required|xss_clean');
  
      $this-&gt;load-&gt;model('manager_model');
  
      $pageData['type'] = 'managers';
      $pageData['title'] = "Edit Manager";
      $data['records'] = $this-&gt;manager_model-&gt;getManager($id);
  
      $this-&gt;load-&gt;view('header', $pageData);
      $this-&gt;load-&gt;view('db_options_view', $pageData);
  
      if ($this-&gt;form_validation-&gt;run() == FALSE)
      {
          $this-&gt;load-&gt;view('managers/editManagerForm_view', $data);
      }
      else
      {   
          $name = $this-&gt;input-&gt;post('name');
  
          $this-&gt;manager_model-&gt;updateRecord($id, $name);
  
          $this-&gt;load-&gt;view('managers/editManagerSuccess_view');
      }
  
          $this-&gt;load-&gt;view('footer');
  }   
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>function updateRecord($id, $name)
  {
      $data = array('name' =&gt; $name);
      $this-&gt;db-&gt;where('id', $id);
      $this-&gt;db-&gt;update('manager', $data);
  }
  </code></pre>
  
  <p>My problem is this. My database table doesnt accept duplicate values for the name field. So while i was testing it i entered a duplicate name and codeigniter returned the following:</p>
  
  <p>A Database Error Occurred
  Error Number: 1062
  Duplicate entry 'alan pardew' for key 2
  UPDATE <code>manager</code> SET <code>name</code> = 'alan pardew' WHERE <code>id</code> = '2'
  Filename: /var/www/vhosts/mysite.com/httpdocs/personal/models/manager_model.php
  Line Number: 74</p>
  
  <p>I would like to handle this error myself in the controller, and I have done a bit of reading up and found that I have to set <code>$db['default']['db_debug'] = FALSE;</code> to prevent codeigniter from displaying the errors. </p>
  
  <p>Is there anyway of just turning particular errors off such as for duplicate entrys?</p>
  
  <p>Or would you recommend switching them off completely?</p>
  
  <p>Also..i'm fairly new to codeigniter so if you can spot any bad practice in my code feel free to point it out!</p>