Hello all. I am trying to connect to multiple databases but testing lines of code one at a time, but I dont get any of my messages to echo out onto the page. Now the question is, does my code fail? Or did i write it wrong? No log is created this time around so I am assuming its not failing (Last time I wrote this and tested, there would be an error log created, this time no error log)
Anyone have any idea??
Code:
<?php
//trys to connect to each database
try {
$db1 = new PDO('mysql:harcerze_******; host=**.***.***.***', '*********', '*********');
} catch (PDOException $ex) {
if($db1 == false)
echo 'Connect Failed: ' .$ex->getMessage();
else {echo 'Connected to DB1';}
};
?>
For want of a nail...the horseshoe was lost. For want of a horseshoe, the steed was lost. For want of a steed...the message was not delivered. For want of an undelivered message.....the war was lost.
Code in the catch{} block will only run if an exception occurs, so you'll never see the success message in there.
PHP Code:
try { $db1 = new PDO('mysql:harcerze_******; host=**.***.***.***', '*********', '*********'); echo "<p>Debug: connected to DB1</p>\n"; $db1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // continue doing whatever you want with $db1 . . . } catch (PDOException $ex) { $msg = $ex->errorInfo; error_log(var_export($msg, true)); die("<p>Sorry, there was an unrecoverable database error. Debug data has been logged.</p>"); };
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks