Welcome Guest, Not a member yet? Register   Sign In
get mysql errors text
#1

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 
I get error message like on my screen : 


PHP Code:
Error Number1054
Unknown column 
'userna' in 'field list'
SELECT `id`, `usernaFROM `bp_usersORDER BY `usernameASC LIMIT 42
Filename
models/Muser.php
Line Number
219 

if
PHP Code:
db_debug false 
I did not find how to log these errors.
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?
Reply
#2

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).
Reply
#3

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB