/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Multiple PDO DB connections

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’;}
};
?>
[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 23.2012 — Code in the catch{} block will only run if an exception occurs, so you'll never see the success message in there.
[code=php]
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>");
};
[/code]
×

Success!

Help @UAL225 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...