⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to make a database error handling?



Apostle

Apostle
  • profile picture
  • Member

Posted 28 December 2012 - 16:57 PM

I could not do it. Approximate my PHP code:
[php]
...

function index()
{
$crud = new grocery_CRUD();

...

// $crud->callback_after_delete(array($this, 'delete_error_number'));
$crud->callback_before_delete(array($this, 'delete_error_number'));

....

$output = $crud->render();

foreach($output->css_files as $file)
$this->data['link'] .= link_tag(str_replace(base_url(), '', $file))."\n";
foreach($output->js_files as $file)
$this->data['script'] .= script_tag(str_replace(base_url(), '', $file))."\n";
$this->data['output'] = $output->output;

$this->load->view('templates/header', $this->data);
$this->load->view('templates/menu', $this->data);
$this->load->view('myview.php', $this->data);
}

function delete_error_number($primary_key)
{
...
if ($error_number == $x)
{
$this->form_validation->set_message('delete_error_message', $primary_key.' To ensure reference (referential, relational, many-to-one relationship) integrity of the database can not be removed. This field is used in the child table.');
return FALSE;
}
else
return TRUE;
}
...
[/php]

I like the quick response ;-)