Search code examples
phpvariablesormconfigurationpropel

How to handle Propel environment variables


I am trying to setup some configuration for unit-testing my application. Therefore I will need to setup different database connections. I have tried to follow the documentation (Environment Variables Doc) but I don't understand where to save the environment variables so they can be found when I have something like:

dsn: "mysql:host=%env%;dbname=%env%"

in the propel.yaml file.

Google does not provide any solutions, as well as searching here.

The Documentation says i have to write them in a file.. but where?

Can somebody help me please?


Solution

  • Env vars

    When using Linux you can set environment vars like this:

    $ export DB_HOST="localhost" 
    $ export DB_NAME="dbname"
    ...
    

    Thus you can grab vars with PHP Like this:

    $ php -r 'var_dump($_ENV["DB_NAME"]);'
    

    Or:

    $ php -r 'var_dump(getenv["DB_NAME"]);'
    

    In order to set env vars on Windows follow this link: How to Create a Environmental Variable Windows 7

    Propel

    On propel, you must set the parameters like (propel.yaml file):

    propel:
      database:
          connections:
              default:
                  adapter: mysql
                  classname: Propel\Runtime\Connection\DebugPDO
                  dsn: mysql:host=%env.DB_HOST%;dbname=%env.DB_NAME%
    

    And here goes some helpful links: