get mysql errors text - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: get mysql errors text (/showthread.php?tid=63976) |
get mysql errors text - mstdmstd - 12-29-2015 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? RE: get mysql errors text - drik - 12-29-2015 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). RE: get mysql errors text - mwhitney - 12-29-2015 https://codeigniter.com/user_guide/database/queries.html#handling-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. |