17

I have an Codeigniter app (using version 2.1.0) that is writing a transaction to a mysql database. I'm fairly sure that I've got a foreign key constraint error occurring, but I can find no way to make CI tell me the specific error. mysql_error() comes back empty.

Can anyone tell me how to get Codeigniter to tell me the mysql error message?

0

2 Answers 2

40

Yes, this is the mysql_error() wrapper.

$this->db->_error_message();

And the mysql_errno wrapper is:

$this->db->_error_number();
4
  • In the current version of CI, those are private functions. Any suggestions on the best way to get access to them with modifying the core files?
    – pbarney
    Mar 27, 2015 at 19:57
  • I don't get this, i mean how to use it. I Tried but get nothing in display. @DRL Jan 18, 2017 at 13:00
  • i've got this -> Call to undefined method CI_DB_mysqli_driver::_error_number(). i'm using php 5.6
    – Mang Jojot
    Jan 16, 2018 at 5:59
  • This answer is deprecated. .check this stackoverflow.com/questions/7843406/…
    – AgentP
    Jul 10, 2022 at 13:51
1

You may be able to use call_function in the db class to access mysql_error:

http://ellislab.com/codeigniter/user-guide/database/call_function.html

Of course, you could also just turn on the debug flag in the DB config, to tell CI to display db errors:

http://ellislab.com/codeigniter/user-guide/database/configuration.html

db_debug - TRUE/FALSE (boolean) - Whether database errors should be displayed.

3
  • When I attempt to use call_function('mysql_error'), I get the following: "This feature is not available for the database you are using." It is an innodb table under mysql. I do have $db['default']['db_debug'] = TRUE in the database.php config file. The most I get is my exception and a stack trace. This is so frustrating. Right now, I'm feeling like going with CI was a big mistake.
    – pbarney
    Jul 13, 2010 at 6:16
  • @pbarney dont give up on it yet, check my answer
    – Bella
    Jul 13, 2010 at 6:47
  • 1
    Also note, as mentioned on the call_function page, you're supposed to pass the name of the function without the mysql_ prefix.
    – Amber
    Jul 13, 2010 at 6:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.