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?

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

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

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
}

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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.