Welcome Guest, Not a member yet? Register   Sign In
Having error message show when stored procedure not successfull
#1

[eluser]bleu[/eluser]
I am using a stored procedure which inserts data in a table.
Now if I am inserting data with a primary key value which already exists in the table, then it should provide an error but currently it is taking me to this page
Code:
A Database Error Occurred

Error Number: 0

call spInsertabc('primary_key_value_which_already_exists','edd')

Filename: models/abc_model.php

Line Number: 46





I would like to return a proper message(such as "Cannot be inserted right now try again" or "Primary key already exists") to the user along with the page on which he submitted the daa if there exists a similar primary key value or if there is an error when inserting data.

How can I achieve that?

I am using codeigniter 2.1.0



#2

[eluser]vrencianz[/eluser]
Use (for example)

Code:
try {
...
// execute query
...

} catch (Exception $e) {
    ...
    // set a message here
    ...
}
#3

[eluser]bleu[/eluser]
[quote author="vrencianz" date="1335285687"]Use (for example)

Code:
try {
...
// execute query
...

} catch (Exception $e) {
    ...
    // set a message here
    ...
}
[/quote]


where will I place this where I have called my stored procedure?

like
try {
$this->db->query("call spInsertabc('primary_key_value_which_already_exists','edd')")
}
catch (Exception $e) {
...
// set a message here
...
}
#4

[eluser]vrencianz[/eluser]

Code:
try
{
  $this->db->query(“call spInsertabc(‘primary_key_value_which_already_exists’,‘edd’)”);
}
catch (Exception $e)
{
  $data['message'] = 'Cannot be inserted right now try again';
}

....
$this->load->view('your_view', $data);
...

where your_view will echo $message




Theme © iAndrew 2016 - Forum software by © MyBB