Jump to content

Connection problems and no error messages output


Yesideez
Go to solution Solved by Yesideez,

Recommended Posts

I have the following code and yesterday this was working and now I get nothing sent to my browser...

<?php
ini_set('display_errors','1');            //only during development
ini_set('display_startup_errors','1');    //only during development
error_reporting(E_ALL);                   //only during development

$options=[
  PDO::ATTR_EMULATE_PREPARES   => false, // turn off emulation mode for "real" prepared statements
  PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION, //turn on errors in the form of exceptions
  PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, //make the default fetch be an associative array
];
try {
  $pdo=new PDO("mysql:host=localhost;dbname=polthouse",'root','',$options);
} catch (PDOException $e) {
  die('Connection failed: ',$e->getMessage());
}
phpinfo();
?>
Edited by Yesideez
Link to comment
Share on other sites

  • Solution
Posted (edited)

FIXED!

 

Somehow my try...catch section, the die() statement I've passed it two parameters as the . to concatenate strings turned into a comma. No idea how that happened but I've changed it to a . and it's all now working perfectly.

 

Although I have no error message appear telling me there was a problem with it.

Edited by Yesideez
Link to comment
Share on other sites

this is a parse/syntax error. to get php to report and display parse/syntax errors, you must have the php error related settings in the php.ini on your system, so that they are in effect before your php script is parsed, tokenized, and executed.

error_reporting should ALWAYS be set to E_ALL. you cannot successfully set display_startup_errors in your code because php has already started by the time your code is running. during development, yes, you should have display_errors set to ON (or 1, e.g. a true value.) when running code on a live/public server, you should have display_errors set to OFF (or 0, e.g. a false value) and log_errors should be set to ON.

the only database exceptions you should catch and handle in your code are for user recoverable errors, such as when inserting/updating duplicate or out of range user submitted data values. in these cases, the catch logic should test the error number and setup a message for the user letting them know what was wrong with the data that they submitted. for all other error numbers, just rethrow the exception and let php handle it. for all other query types and all other database statements that can fail, do nothing in your code and let php handle any database exception. when you let php catch and handle the database exception, php will 'automatically' display or log (using the php error related settings) the actual error information for you via an uncaught exception error.

Link to comment
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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.