News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ilia Alshanetsky's Blog:
Database connection fallback with PDO
June 04, 2012 @ 09:50:26

Ilia Alshanetsky has a new post to his blog sharing a method for fallback with PDO when your database connection fails.

For our database connections we PDO at work and we've extended the class with PHP to offer some other convenience functionality and wrappers. One of the things I wanted to do recently is allow the constructor of the PDO class to fail-over to our backup database connection pool in the event the primary was not available.

He wanted his code to catch an exception if the object was created with a failed server host and to connect to the backup instead. PDO doesn't cooperate with this method and just destroys the object when there's a failure. His work around is in this patch to the PDO support in PHP to provide a new constant, PDO:: ATTR_KEEP_CLASS_CONN_FAILURE, that tells the script wether or not to destroy the PDO object when there's a problem.

0 comments voice your opinion now!
database connection failover pdo patch


Evolt.org:
Failover Database Connection with PHP + mySQL
May 21, 2007 @ 12:04:00

Evolt.org has a recently posted tutorial that talks about creating a simple failover database connection for your PHP and MySQL application.

Imagine, you're connecting to a mySQL database with PHP, but hell, you want a bit more robustness. So why would you want just one database? You'd use a failover right? So if the first database is down or just doesn't connect, it can connect to the next one. Here's how to do that (I'm assuming you're already replicating between databases so that they're roughly in sync). Here's how you do it.

The tutorial walks you through the creation of a simple MySQL connection, but with two sets of credentials. The script tests the connection to the first database and, if it doesn't get a valid resource back, it falls back on the secondary. Of course, keeping the data in sync is your job.

0 comments voice your opinion now!
failover database connection mysql support tutorial failover database connection mysql support tutorial



Community Events





Don't see your event here?
Let us know!


symfony laravel framework opinion series language security composer application voicesoftheelephpant install version library release introduction podcast interview package community tool

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework