Accessing Symfony 1.0 Database attributes

I am still using Symfony 1.0 for a project, mainly because of the number of plugins that are being used, but that’s another story.

I came across a problem when trying to introduce an external class that allowed backups of a MySQL database.
I wanted to reuse the DSN of the Symfony application (i.e. Username, Password, etc..) but couldn’t find an easy way of getting the information.

I found that the following code provided the database connection object which included the DSN.

sfContext::getInstance()->getDatabaseConnection('propel')

By using the following code I could then access an associative array of the DSN:

$con=sfContext::getInstance()->getDatabaseConnection('propel')
->getDSN();
$username = $con['username'];
$password = $con['password'];
$database = $con['database'];
$host = $con['hostspec'];
etc...

Using this associative array I could then pass on the respective attributes to my third party class with little effort.

thanks

adam

Posted by Adam

Post to del.icio.us Post to del.icio.us

Post to Slashdot Post to Slashdot

Digg this Digg this

This entry was posted on Friday, March 5th, 2010 at 7:48 pm and is filed under Tags: , . You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.