News Feed
Sections




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

Gonzalo Ayuso:
Handling several PDO Database connections in Symfony2 through the DIC in PHP
January 08, 2013 @ 11:52:40

Gonzalo Ayuso has written up a new post about a handling method he's worked up for working with multiple PDO instances (database connections) through the Symfony2 dependency injection container using custom YML definitions and a simple "Db" class.

I'm not a big fan of ORMs, especially in PHP world when all dies at the end of each request. Plain SQL is easy to understand and very powerful. Anyway in PHP we have Doctrine. Doctrine is a amazing project, probably (with permission of Symfony2) the most advanced PHP project, but I normally prefer to work with SQL instead of Doctrine. [...] Due to my daily work I need to connect to different databases (not only one) in my applications.

He shows the normal setup using the "parameters.yml" file to define the multiple database connections but notes that this isn't the most ideal solution. Instead, he walks you through the steps to create the "databases.yml" configuration file and a simple "Db" class that acts as an interface to pull the PDO objects from the container. You can then just call the "get" method on the container to extract the fully configured PDO object, ready for use.

0 comments voice your opinion now!
pdo symfony2 connection tutorial multiple yml database


blog comments powered by Disqus

Similar Posts

Anthony Wlodarski's Blog: Node.js and Zend Auth with Sessions stored in the database

Mike Purcell's Blog: Symfony - PHP - Possibly Forking 1.x so Invested Companies donít Lose Millions

MongoDB Blog: MongoDB for the PHP Mind, Part 1

Sebastian Begmann's Blog: Partitioning with Dates in MySQL 5.1

Sara Goleman\'s Blog: PDO_User and the effects of Slide Driven Development


Community Events





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


code series introduction symfony2 refactor podcast developer release testing opinion language laravel install community framework unittest api threedevsandamaybe list interview

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