MySQL configuration is stored in config/databases.yml. Use the code below to get the parameters in an action.
$databaseConf = sfYaml::load(sfConfig::get('sf_config_dir') . '/databases.yml');
$params = $databaseConf ['all']['doctrine']['param'];
$dsn = $params['dsn'];
$username = $params['username'];
$password = $params['password'];
$database = substr($dsn, strpos($dsn, 'dbname=')+7);
Only works if your dns parameter does not contain anything after the database's name, ex: dsn: mysql:host=localhost;dbname=thenameofthedatabase
No comments:
Post a Comment