Accessing Symfony 1.0 Database attributes
Friday, March 5th, 2010I 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
