Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 107
  • Last Modified:

PDO Error Reporting

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
APD Toronto
Asked:
APD Toronto
  • 5
  • 3
1 Solution
 
Ray PaseurCommented:
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
 
APD TorontoAuthor Commented:
I just wanted to know if I can ask the provider to change something (ex: php.ini) in order to enable errors?
0
 
Ray PaseurCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
The relevant man page that describes all of this is here:
http://php.net/manual/en/book.errorfunc.php
0
 
APD TorontoAuthor Commented:
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
 
Ray PaseurCommented:
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
 
APD TorontoAuthor Commented:
Where do you set Error Reporting (E_ALL)?
0
 
Ray PaseurCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now