get mysql errors text |
Hello,
Making rest api using CodeIgniter 3.0.3 I want in case of mysql error to return error description in json return block In case of PHP Code: db_debug = true PHP Code: Error Number: 1054 if PHP Code: db_debug = false I googled and found : PHP Code: $this->db->call_function('error') and $this->db->call_function('errno') where $this - is current control but they show nothig Also I found : Quote: Currently it seems we can't get query error message since _error_messageand _error_number are protected methods. I use 'dbdriver' = 'mysqli' Which is the good way to get errors text in this case?
For debugging your errors, you will find the logs for each day (if set so in config.php) in [ci dir]/application/logs/
For working something out on the front-side (json), you have to catch and process those errors yourself. Then you can output this to a specific mime type such as json (see user guide on Output Class).
https://codeigniter.com/user_guide/datab...ing-errors
Use $this->db->error(), which should return an associative array with the keys 'code' and 'message', which should be self-explanatory. Under certain conditions, like a connection error, this might not return valid error information. However, in cases like your example, it should provide the information you're looking for. |
Welcome Guest, Not a member yet? Register Sign In |