News Feed
Jobs Feed

News Archive
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

blog comments powered by Disqus

Similar Posts MySQL replication in PHP - on the same machine Learn to Create Interactive Drill-Down Dashboards with PHP and FusionCharts

Wez Furlong: OpenID (and TypeKey) using native OpenSSL functions in PHP

IBM developer Works: PHP and RSS: Getting it together Using an Access Database with PHP

Community Events

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

composer hack hhvm opinion package symfony2 application install release podcast component threedevsandamaybe code facebook introduction framework series security language unittest

All content copyright, 2014 :: - Powered by the Solar PHP Framework