Welcome Guest, Not a member yet? Register   Sign In
How to prevent CI from dumping SQL on screen when err occurs?
#1

[eluser]starenka[/eluser]
How to prevent CI from dumping SQL on screen when error occurs? These messages are pretty fancy while developing, but it's a hazard show such data on production servers.. anybody can put me into it? thanx
#2

[eluser]starenka[/eluser]
Or how can i change such messages? Im used to handle errors myself like:

Code:
if(!query) show_error(....)

but CI, stops the script execution on db error and puts up it's own message....
#3

[eluser]gtech[/eluser]
Hello,

You can stop the database class from halting execution by setting db_debug to FALSE in the database.php file contained in the config directory. This will also speed you database queries up Smile

I have caught errors using the following mechanism once db_debug is off:
Code:
...
    $dbRet = $this->db->insert($table, $dataArray);
    if (!$dbRet) {
      $errNo   = $this->db->_error_number()
      $errMess = $this->db->_error_message();
    }
...
See discussion 61557.. I have mentioned this a few times in the forum but seems to answer your question I hope
#4

[eluser]starenka[/eluser]
kool. thx
#5

[eluser]gtech[/eluser]
no problems, its a shame the db->_error_ number & db->_error_message functions are not documented in the main documentation, it would also be good if these functions were not internal (preceding underscores), but it still works as above.
#6

[eluser]iive[/eluser]
agreed. I think it is good for us to customize the how the error message should be displayed on screen to maintain the site apprearance across all the pages.
#7

[eluser]Phil Sturgeon[/eluser]
They arent documented as they are only really intended for internal use by that class. If this was a PHP5 app you probably wouldnt able to get at them at all! Good old PHP4...
#8

[eluser]gtech[/eluser]
I know they are intended for internal use.. but its would be very easy to write an external function that just calls the internal function... I am writing a middleware management application that talks to hardware and will be used my multiple web based GUIS, so I need to return a clean error message back to the GUI application without the application halting. I have seen multiple forum posts where people want to be able to do this.

If you want to call these functions without calling the internal functions directly, just put these functions in system\database\DB_Driver.php

Code:
..
  function error_message() {
    $this->_error_message()
  }
  function error_number() {
    $this->_error_number()
  }

I am also using PHP5 and calling the internal functions directly still works!

As these functions are used to display the standard CI database error message when db_debug is TRUE. Is there any reason why they are internal only?
#9

[eluser]gunter[/eluser]
you can switch the messages off
config/database.php

Code:
$db['default']['db_debug'] = FALSE;
// db_debug - TRUE/FALSE (boolean) - Whether database errors should be displayed.
#10

[eluser]gtech[/eluser]
[quote author="gunter" date="1194808677"]you can switch the messages off
config/database.php

Code:
$db['default']['db_debug'] = FALSE;
// db_debug - TRUE/FALSE (boolean) - Whether database errors should be displayed.
[/quote]

yes you have to do that for the code to work in reply 3, if you don't you cant catch the errors.

does anyone know why db->_error_message and db->_error_number are internal only?




Theme © iAndrew 2016 - Forum software by © MyBB