Snippets

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

Navigation

Using multiple databases from Propel

if you using multiple database from Propel, It can be solve by writing two or more schema files.

PROJECT_DIR/config/databases.yml

all:
  database1:
    class:   sfPropelDatabase
    param:
      dsn:   pgsql://foo:bar@hostname/database1

  database2:
    class:   sfPropelDatabase
    param:
      dsn:   mysql://foo:bar@hostname/database2

PROJECT_DIR/config/database1.schema.xml

<?xml version="1.0" encoding="UTF-8"?>
<database name="database1" defaultIdMethod="native" noxsd="true">
  <table name="foo" phpName="Foo">
    ....
  </table>
</database>

PROJECT_DIR/config/database2.schema.xml

<?xml version="1.0" encoding="UTF-8"?>
<database name="database2" defaultIdMethod="native" noxsd="true">
  <table name="bar" phpName="Bar">
    ....
  </table>
</database>

Last, build model command.

$ symfony propel-build-model

Build complete.

Example, getting multiple databases connection handler.

$database1_connection_handler = Propel::getConnection(FooPeer::DATABASE_NAME);
$database2_connection_handler = Propel::getConnection(BarPeer::DATABASE_NAME);
by Kota Sakoda on 2006-08-30, tagged database  model  propel 

Comments on this snippet

gravatar icon
#1 Pierre Minnieur on 2006-08-30 at 04:08

So, I was thinking about "outsourcing" my authentication and permission management into a second database, so that queries in a module can't afflict this sensible tables. But I can't figure where I have to put the things with the Propel::getConnection - in the Model? In the BaseModel? Or will symfony/propel handle this automatically with setting the correct connection in the model while propel builds it? I'm a bit ... confused ;)

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