-
- Item
- 25 September 2009
- Jaymon
rebuilding the db schema #symfony #learned
1 - update config/schema.yml 2 - "php symfony propel:build-sql" from the command line, that will build the correct propel crap from the schema.yml 3 - now, here you should be able to just run "php symfony propel:insert-sql" but I always get a [wrapped: invalid data source name] error that I have no idea what it means, so you can also do: > mysqladmin -u root -p create DB_NAME > mysql -u root -p DB_NAME < data/sql/lib.model.schema.sql obviously you don't have to do the "mysqladmin" command if you have already created the db, and you don't have to worry about the -p (password) if your localhost root has no password. You can also open the XAMPP phpAdmin and import the lib.model.schema.sql file into your db that way. 4 - then, if you changed your schema you will want your model bases to reflect the change, so delete the cache (delete everything in the cache folder) and then run: "php symfony propel:build-all" to rebuild everything, the documentation says to use "php symfony propel:build-model" but that doesn't redo all the base* classes of the model I got all this from the middle and bottomish part of http://www.symfony-project.org/book/1_2/08-Inside-the-Model-Layer propel:data-load in ch16 will also let you import data from a text file, to populate your db To just rebuild the sql and the classes: php symfony propel:build-sql php symfony propel:build-all --classes-only
-
- Item
- 3 March 2011
- Jaymon
Multiple databases support in Symfony - Stack Overflow #learned
how to allow your #symfony app to support more than one db. http://stackoverflow.com/questions/733224/multiple-databases-support-in-symfony
-
- Item
- 3 March 2011
- Jaymon
building a db driver plugin in symfony #symfony #learned
this turned out to be harder than I expected due to the lack of documentation on how to build a database driver since I guess people that use Symfony are happy with either Propel or Doctrine.
The first problem I had was how to get configuration info to my new custom ORM. I started with databases.yml:
===== the databases.yml file =====
ENVIRONMENT:
propel:
param:
classname: DebugPDO
dsn: mysql:dbname=ENVIRONMENT;host=localhost
username: USERNAME
password: PASSWORD
OTHER_ORM:
param:
name: DB_NAME
host: localhost
username: USERNAME
password: PASSWORD
all:
propel:
class: sfPropelDatabase
param:
phptype: mysql
classname: PropelPDO
encoding: utf8
persistent: true
pooling: true
OTHER_ORM:
class: sfOtherOrmDatabase
=====
now, the "class" variable is important, because in your plugin directory you need something like the following structure:
=====
sfOtherOrmPlugin/
config/
sfOtherOrmPluginConfiguration.class.php
lib/
database/
sfOtherOrmDatabase.class.php
...
=====
Notice that sfOtherOrmDatabase.class.php maps to "class: sfOtherOrmDatabase" in the .yml file.
the sfOtherOrmDatabase class needs to extend the sfDatabase class and implement connect() and shutdown() methods.
The sfOtherOrmPluginConfiguration class needs to extend the sfPluginConfiguration class and implement initialize().
Now, where I got hung up is actually connecting, I thought by implementing connect(), Symfony would call connect() automatically, but it doesn't. And, since I was using Propel code as my template, I was confused because Propel never actually calls sfPropelDatabase::connect(), it uses its own Propel::getConnection() instead.
However, initialize is always called, so I decided my custom class would connect on initialization, so let's go ahead and extend sfDatabase::initialize to call connect():
===== sfOtherOrmDatabase::initialize() =====
public function initialize($parameters = array())
{
parent::initialize($parameters);
$this->connect();
return true;
}//method
=====
Now my custom db orm automatically connects and is ready for use when I get into the controller. And I am free from Propel and Doctrine so I can use databases like MongoDb.