1

I have a mysql Stored procedure that is called when a user should be deleted. Procedure signals an SQL state and throws error when someone tries to delete the row of Administrator Account. My Code in procedure is -

SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Adminstrator cannot be deleted';

I am using CodeIgniter 3.1. I want to catch this error message WITH its sql state in my code. I looked into following links but no help -

1) CodeIgniter - how to catch DB errors?

2) Database Error Handling problem in CodeIngniter

What I observed was that there was a method $this->db->_error_number(); that could be used to get error number/sql state, but this is deprecated in latest version.

I wanted to know is there any way in CodeIgniter to get the SQL State if the database error occurs?

Any help would be appreciated.

3

1 Answer 1

3

The function you mention has been deprecated:

Replaced the _error_message() and _error_number() methods with error() - which returns an array containing the last database error code and message."

https://www.codeigniter.com/userguide3/changelog.html?highlight=_error_number#version-3-0-0

See https://www.codeigniter.com/userguide3/database/queries.html#handling-errors for details.

Sign up to request clarification or add additional context in comments.

1 Comment

CI's error() is empty during SQLSTATE 45000. I don't understand this behavior. Looks like it only shows error generated by my MySQL but not coming from user-defined errors from stored procedures and triggers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.