Symfony2 ClearDB configuration on Heroku

Can someone directly tell me how to connect my symfony2 application to ClearDB on heroku?

I got a connection string on the hero by typing

$ heroku config

but when I put the results on my .yml options, I get the message SQLSTATE [HY000] [2002] Connection failed.

Thanks in advance

+4
source share
1 answer

This will help someone else like me:

  • Put the connection settings in parameters.phpinstead parameters.yml, as shown below

    <?php
    
    // Using ClearDB for mysql database
    $db = parse_url($_ENV['CLEARDB_DATABASE_URL']); 
    $container->setParameter('database_driver', 'pdo_mysql'); 
    $container->setParameter('database_host', $db['host']); 
    $container->setParameter('database_port', '~');
    $container->setParameter('database_name', trim($db['path'], '/')); 
    $container->setParameter('database_user', $db['user']); 
    $container->setParameter('database_password', $db['pass']);
    
    // Using Mandrill to send email
    $container->setParameter('mailer_transport', 'smtp');
    $container->setParameter('mailer_host', 'smtp.mandrillapp.com');
    $container->setParameter('mailer_user', $_ENV['MANDRILL_USERNAME']);
    $container->setParameter('mailer_password', $_ENV['MANDRILL_APIKEY']);
    
    // Other settings
    $container->setParameter('locale', 'en');
    $container->setParameter('secret', 'your_secret');
    
    ?>
    
  • Include parameters.phpin your configuration file:

    imports: - { resource: parameters.php} 
    
+2
source

All Articles