Jump to content
Sign in to follow this  
j.silver

Lack of Error Reporting

Recommended Posts

Hi all,

 

<?php

require 'db/connect.php';
$result = $db->query("SELECT * FROM people");
?>
I obtained a blank page running the above script, which indicates that everything is fine (path and table name are correct). I then removed the * from the query to see if it would report an error, but it did not. I added print_r($result); and run it. Nothing has changed. I included the * and run, it reported the number of rows and columns in the table.
Why there has a been a lack of error reporting in this instance, noting that the ini file is configured to report all sorts of errors, even the warnings and notices (and it is reporting all that in other scripts)?

Share this post


Link to post
Share on other sites

What type of object is $db?

 

PDO won't throw errors unless you specifically tell it to. $db->query() will just return false if the query is wrong.

 

If you're using PDO, be sure to set the error mode http://php.net/manual/en/pdo.setattribute.php

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Share this post


Link to post
Share on other sites

I believe mysqli does not throw errors either, you have to test that the query returns false.

You can also set error reporting with $mysqli_driver->report_mode

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...