Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PDO Error Reporting

Posted on 2015-02-21
8
Medium Priority
?
94 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
[X]
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
8 Comments
 
LVL 111

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 111

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 111

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
 

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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 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