PDO Error Reporting

Posted on 2015-02-21
Last Modified: 2015-02-23
Hi Experts,

I have the following PDO connection

    public function getDB() {

        global $env;
        $dsn = 'mysql:host=' . $env['db_server'] . ';dbname=' . $env['db_name'] . ';';
        $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
        //One connection per browser session
        if (!isset($db)) {
            self::$db = new PDO($dsn, $env['db_user'], $env['db_password'], $options);            
        return self::$db;

Open in new window

Please note of my $options.

Now, on my local machine if I purposly make an invalid SELECT statement, the browser gives me an error (as expected), but on the server I just get a blank page, even with my $options above.

Why is this, and how can I make the server throw errors as my local machine? Is it something in php.ini? Is there a value I can look for under phpInfo();?

Thank you
Question by:APD_Toronto
  • 5
  • 3
LVL 108

Expert Comment

by:Ray Paseur
ID: 40623737
You may want to check your settings for error_reporting() and you may want to try using error_log()  to see how these functions work on your local machine.  In my preferred dev environment, I upload all of my work via a "one-touch-build" to an online web server that lives in a parallel universe to my deployment environment.  I do my testing there.  It gives me a nearly-live environment to test my work over the internet in a server that is a lot like what I will use when I deploy.

A simple test can tell you if you will see the error messages.

trigger_error("Test", E_USER_NOTICE);
trigger_error("Test", E_USER_WARNING);
trigger_error("Test", E_USER_ERROR);

Open in new window


Author Comment

ID: 40624337
I just wanted to know if I can ask the provider to change something (ex: php.ini) in order to enable errors?
LVL 108

Expert Comment

by:Ray Paseur
ID: 40624351
Yes, your provider can change the error reporting level.  You can check the error reporting levels with phpinfo();  Scan the output for "error" to find the various settings that are in effect.
LVL 108

Expert Comment

by:Ray Paseur
ID: 40624352
The relevant man page that describes all of this is here:
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails


Author Comment

ID: 40624459
The table below shows different directive values between my machine and the server, and my assumption is that i need to ask the provider to match my settings?

By the way, what is error_reporting 22527 / 32759?

Directive      Dev Machine      Server
display_errors      On      Off
error_log      C:\...      No Value
*error_reporting      22527      32759
html_errors      on       off
LVL 108

Expert Comment

by:Ray Paseur
ID: 40624484
Yes, I think I would ask the server provider to at least enable the error_log and set the value to "error_log" - that way you will get an error log created in the directory where the error occurred.

I do not know what the error_reporting settings are by number.  I always use error_reporting(E_ALL).  This may or may not work for you.  The PHP default is to suppress Notice messages and some programs have been written to accept undefined variables as if they were zero, false, empty strings, etc.  Personally I think this is a terrible default position, but it's too late to fix it in native PHP (most frameworks have fixed it, but many PHP web sites do not use frameworks).

Here are my php.ini settings related to errors.  I manually set error_reporting(E_ALL) in my scripts.

display_errors = On
log_errors = On
log_errors_max_len = 1024
error_log = error_log

Author Comment

ID: 40624486
Where do you set Error Reporting (E_ALL)?
LVL 108

Accepted Solution

Ray Paseur earned 500 total points
ID: 40624559
I set it manually in my scripts, like this code snippet, but it can be set as a site-wide default, too.

I checked, and the E_ALL setting evaluates to number 32767 on PHP 5.4.37+


 * Description here


Open in new window


Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Button Click 11 26
PHP connection to remote AWS MySQL RDS 4 41
PHP loop not working 4 33
Help cleaning out CSS 2 31
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now