/    Sign up×
Community /Pin to ProfileBookmark

Failover script for MySQL

Can anyone help me with modifying the following connection script? I want to modify it for this type of scenario:

if (!productiond? // Can’t connect to database (it’s either down or timesout)
connect testdB;

Here’s an extract of my script:

$db = @mysql_connect($host, $user, $pwd) or die (mysql_error($err . mysql_error()));
mysql_select_db($database);

is there a database abstraction layer that has that sort of functionality already built in?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@DaiWelshApr 07.2005 — $db = @mysql_connect($host, $user, $pwd) or die (mysql_error($err . mysql_error()));

if(!$db) {

$db = @mysql_connect($devhost, $devuser, $devpwd) or die (mysql_error($err . mysql_error()));

}

mysql_select_db($database);

should do what I think you are asking, that is try to connect to one database then if it fails try to connect to another?

There are various classes to do database abstraction, but no single accepted one I am aware of. Some people use PEAR (a full framework not just db) but I have never tried it myself. personlally I would suggest you just write your own db abstraction either as a set of functions or preferably as a class. For basic functionality it should not be hard enough to qualify as "reinventing the wheel"?

HTH,

Dai
Copy linkTweet thisAlerts:
@kouki0196authorApr 07.2005 — I thought it would be that simple. Thanks for the feedback...
×

Success!

Help @kouki0196 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 5.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...