Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Change database connection settings dynamically

To modify the settings of a connection named 'propel':

$con = sfContext::getInstance()->getDatabaseConnection('propel');
$con->setConnectionParameter('username', 'foo');
$con->setConnectionParameter('password', 'bar');

This works for all the settings that can be defined in the databases.yml (more info in the sfPropelDatabase class source).

You must execute this code before the first query to the database. If you do that after a first query, it fails. This means that the best way to implement it is in a filter.

by Francois Zaninotto on 2006-06-20, tagged connection  database  propel 

Comments on this snippet

gravatar icon
#1 Konrad Riedel on 2007-07-30 at 08:04

Doesn't work for me:

Fatal error: Call to undefined method MySQLConnection::setConnectionParameter()

You need to create an account or log in to post a comment or rate this snippet.