Solved

PDO Error Reporting

Posted on 2015-02-21
8
71 Views
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
0
Comment
Question by:APD_Toronto
  • 5
  • 3
8 Comments
 
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.

<?php 
error_reporting(E_ALL);
trigger_error("Test", E_USER_NOTICE);
trigger_error("Test", E_USER_WARNING);
trigger_error("Test", E_USER_ERROR);

Open in new window

0
 

Author Comment

by:APD_Toronto
ID: 40624337
I just wanted to know if I can ask the provider to change something (ex: php.ini) in order to enable errors?
0
 
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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40624352
The relevant man page that describes all of this is here:
http://php.net/manual/en/book.errorfunc.php
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:APD_Toronto
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
0
 
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
0
 

Author Comment

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

Accepted Solution

by:
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+

<?php 

/**
 * Description here
 */
error_reporting(E_ALL);

// REST OF SCRIPT HERE

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 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

16 Experts available now in Live!

Get 1:1 Help Now