A fresh supply of thoughts about Web Development & Mac OS X
Multiple database connections are a great feature, but if you plan to generate a schema for each database, you will most certainly run into some problems caused by different connection names. This Howto will show you how to solve the problem.
Let’s start by defining our database connections: open up the file config/databases.yml and create at least two connections with different names (like „database” and „database1”).
all:
database:
class: sfPropelDatabase
param:
dsn: mysql://ptest:ptest@localhost/ptest
database1:
class: sfPropelDatabase
param:
dsn: mysql://ptest:ptest@localhost/ptest2
In the config/propel.ini configuration file, go to the the sixth line and edit the „propel.database.url” setting so that it matches the first database connection.
propel.database.url = mysql://ptest:ptest@localhost/ptest
Now we can execute the propel-build-schema command.
The next little problem is that the schema generator always assumes that a connection is named „propel” but since we’ve named it „database”, we need to open the just generated schema file and rename the connection (second line).
Before we go on and generate the second schema, we first need to rename the current one or otherwise symfony would just overwrite it.
mv config/schema.yml config/1_schema.yml
(Note: schema files must end with „schema.yml”)
The procedure to generate the schema for the second connection is basically the same as for the first one:
Finally, we can execute the propel-build-model command and are ready to use our databases.
Published: January 8, 2008 — Tagged: creole, multiple database-connection, php, propel, symfony
© 2008 Arthur Koziel — About | Archive | Colophon | Contact | Feeds
Comments
Very good point!
I wonder what is the performance effect on such a configuration….
Do you have some details about it?
The only thing you’ll notice is that a second “connect” command is used (which doesn’t even need 1ms). It works beautifully.