I have a symfony action that creates a mysqldump of the database :
public function executeBackup(sfWebRequest $request)
{
$dump = `mysqldump -u root -proot ec2`;
$fp = fopen("php://temp", 'r+');
fputs($fp, $开发者_StackOverflow中文版dump);
rewind($fp);
$this->setLayout(false);
header('Content-Type: application/gzip');
header('Content-Disposition: attachment; filename="db.sql"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
$this->fichier = stream_get_contents($fp);
}
I've written the database login and password (root/root) in the action, but how can I get them from the yml configuration ?
Look at the code of this plugin, it's pretty self-explanatory.
I've found this answer on the old Symfony forum.
So retrieving login and password from databases.yml should look like:
$file = sfConfig::get('sf_config_dir').'/databases.yml';
$config = file_exists($file) ? sfYaml::load($file) : array();
$db_params = $config['prod']['propel']['param']; // should follow the databases.yml structure
$username = $db_params['username'];
$password = $db_params['password'];
HTH
精彩评论