Welcome Guest, Not a member yet? Register   Sign In
How to catch database exception and not display it to browser
#1

[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
#2

[eluser]stommert[/eluser]
Hi,

if you enable logging by raising the log threshold in your config file,
Code:
$config['log_threshold'] = 1;
you don't have to write it yourself.
otherwise... good luck.

gr
#3

[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?
#4

[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;
check the manual that corresponds to your MySQL server version for the right syntax to use near
'tbl_linkpartner_type_translations.translation_id =  1 ORDER BY tbl_linkp' at line 11
this will be written in your log.
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
#5

[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?
#6

[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;
to
Code:
$db['default']['db_debug'] = FALSE;
succes...
#7

[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;
to
Code:
$db['default']['db_debug'] = FALSE;
succes...[/quote]

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.




Theme © iAndrew 2016 - Forum software by © MyBB