0

Hi all,

I'm trying to figure out how to stop MySQL errors being displayed to the user.

I have turned off all the necessary options in php.ini such as

display_errors = Off
log_errors = On
error_log = /path/to/log/

I have even tried to override these settings using ini_set() in my script.
This prevents PHP syntax errors from being displayed, but Mysql errors are still being shown to the user!

How do I turn this off?

4
Contributors
6
Replies
11
Views
6 Years
Discussion Span
Last Post by somedude3488
0

Just use @ operator in the possible area of occuring the MySql errors in php code. This will hides the MySql errors to display...

0

Yes I have used the suppression operator but this isn't ideal. The user will still get an error message in some circumstances.

E.g, this code:

@ $dbconnect = mysql_connect("ipaddress", "username", "");
        mysql_select_db("db");

This still displays the error:

Access denied for user 'user'@'domain' (using password: NO)

I want the errors to be logged, and NOT displayed to stdout at all!

Surely there's a way to do this...?

Edited by nonshatter: n/a

0

Never mind, I've created my own error handling function for mysql errors. Instead of suppressing the error messages (which isn't particularly useful in a lot of situations), I've used a file handle to write these errors to my own log file:

This means users don't get hold of info they shouldn't. And this way I'll be made aware of the errors instead of them being silenced by using '@'

E.g:

mysql_select_db("db") or (writeErrors(mysql_error(),$ip,$date,__FILE__,__LINE__));

function writeErrors($error,$ip,$date,$file,$line)
{
    //write to the logfile
}
0

That's ok... Just check your ftp username and password if you are working in remote server or mysql username and password if you are working in localhost...

0

I have turned off all the necessary options in php.ini such as
display_errors = Off
log_errors = On
error_log = /path/to/log/
I have even tried to override these settings using ini_set() in my script.
This prevents PHP syntax errors from being displayed, but Mysql errors are still being shown to the user!

How do I turn this off?...

0

Is there an "or die()" statement in your database handler?

Also, never use inline error suppression. Its not very good performance wise.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.