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.

Community
  • 1
  • 1
Rehban Khatri
  • 924
  • 1
  • 7
  • 19

1 Answers1

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.

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
TV-C-1-5
  • 680
  • 2
  • 13
  • 19
  • 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. – tatskie Apr 13 '21 at 00:43