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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 110

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 110

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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 110

Expert Comment

by:Ray Paseur
ID: 40624352
The relevant man page that describes all of this is here:

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 110

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 110

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

734 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