PHP Error Reporting

I’m not sure if this is CentOS 4.x related, InterWorx related or both…

I have this test script:

<?php
error_reporting(2048);
$connection = mysql_connect("localhost","nosuchuser","nosuchpass") or die("Sorry, PHP was unable to connect to MySQL");
?>

On my new CentOS/InterWorx server, the output is this:

Sorry, PHP was unable to connect to MySQL

On another server, as one would expect errors to be shown, the output is this:

Warning: mysql_connect(): Access denied for user ‘nouser’@‘localhost’ (using password: YES) in /var/www/html/test-errors.php on line 3
Sorry, PHP was unable to connect to MySQL

Two (related) questions:

1, How can I allow users to change the Error Reporting thing (as it obviously isn’t letting me);

2, How can I make it show errors like it does in the second example, as they’re normally shown on almost all PHP installations?

Thanks :slight_smile:

The default php installation has display_errors off by default in /etc/php.ini. You can change it there, and restart the webserver. This can also be changed via a .htaccess setting,

php_value display_errors On

And error_reporting setting is working, it just appears that the value 2048 doesn’t include Warnings. If you enable the display_errors option, and call error_reporting() like:

error_reporting( E_ALL );

you should definately see the error/warning you’re looking for.

Paul

Thanks a lot Paul :slight_smile:

Fixed but broken

I’ve copied the warning setting line from a php.ini on a test server (which runs ubuntu/apache2/php5), but the errors are displaying too much.

Even at the top of some normally-working forums, two new errors (the same error, but twice) were introduced, which I’ve never seen before:

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of runtime function name. If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /home/username/domain.com/html/forums/sources/classes/class_display.php on line 347

This is the line I used in php.ini:

error_reporting  =  E_ALL & ~E_NOTICE & ~E_STRICT

Setting this in php.ini also seems to do nothing:

allow_call_time_pass_reference = On

Did your restart Apache after editing the php.ini? Also, you may want to do:

error_reporting  =  E_ALL & ~E_NOTICE & ~E_STRICT & ~E_WARNING

Socheat

If I remove warnings, I won’t see errors like this:

Warning: mysql_connect(): Access denied for user ‘nouser’@‘localhost’ (using password: YES) in /var/www/html/test-errors.php on line 3

I did restart the httpd process several times too…