How to catch database exception and not display it to browser - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How to catch database exception and not display it to browser (/showthread.php?tid=28866) |
How to catch database exception and not display it to browser - El Forum - 03-23-2010 [eluser]chandrajatnika[/eluser] In CodeIgniter, how to catch exception from query error or other database error, so I can customize exception behaviour like save it to log file or anything. And error that occured didn't displayed on browser, just a white blank or an error page without error description. I've tried to create MY_DB_driver to overwrite CI_DB_driver display_error function, but I didn't work because CI_DB_driver is called from CI_Loader. I think it's to complicated for a simple job like this. Could you tell me the easiest way to do this? Regards How to catch database exception and not display it to browser - El Forum - 03-24-2010 [eluser]stommert[/eluser] Hi, if you enable logging by raising the log threshold in your config file, Code: $config['log_threshold'] = 1; otherwise... good luck. gr How to catch database exception and not display it to browser - El Forum - 03-24-2010 [eluser]chandrajatnika[/eluser] it just enabling logging, what I want is get the error string then I use for another purpose. how to do it? How to catch database exception and not display it to browser - El Forum - 03-24-2010 [eluser]stommert[/eluser] you probably have to proces the log file. When a database / query error occurs, something simular to Code: ERROR - 2010-03-01 09:43:36 --> Query error: You have an error in your SQL syntax; 1. So you could search for 'Query error:' and do whatever you like with the result. 2. You could extend the logging library and insert it in a db table and than query it. You might want to be careful with this option, because this table has the potential to grow fast.here is a link on extending the log library How to catch database exception and not display it to browser - El Forum - 03-24-2010 [eluser]Shiro[/eluser] how about disable the db error message display at browser, I also try to set -index.php error_reporting(0); -config.php $config['log_threshold'] = 1; but the webpage still display the error, anyway to disable it? How to catch database exception and not display it to browser - El Forum - 03-24-2010 [eluser]stommert[/eluser] I don't know why you are posting this message on this thread, and what the problem is with the excellent user guide, but here we go (again); Database errors are configured in the database config. If you don't want them to be outputted to the browser. Just set Code: $db['default']['db_debug'] = TRUE; Code: $db['default']['db_debug'] = FALSE; How to catch database exception and not display it to browser - El Forum - 03-24-2010 [eluser]Shiro[/eluser] [quote author="stommert" date="1269437543"]I don't know why you are posting this message on this thread, and what the problem is with the excellent user guide, but here we go (again); Database errors are configured in the database config. If you don't want them to be outputted to the browser. Just set Code: $db['default']['db_debug'] = TRUE; Code: $db['default']['db_debug'] = FALSE; Many Thanks for your information, I just think about set php error to turn off, dont have a thought disable from db_debug. Really thank you for your patient and your help. |