Php Orm with database from model

ormPHP

I'm pretty used to Django. With Django you define your models for the ORM and it takes care of generating / altering the database itself for storing the data based on the models.

In php i'm looking for a similar solution. Doctrine seems to be the standard php ORM, but, as far as I've seen, you have to write the DB and then attach to it, or script the database creation, then generate the models and start working.

Is there a one step model definition to db creation with Doctrine or another php orm solution? Thanks.

Best Answer

Are you that only the ORM in Django itself is responsible for creating the DB and all that stuff?

But Doctrine can do the setup automatically. I copied the most important part:

// generate.php

require_once('bootstrap.php');

Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::generateModelsFromYaml('schema.yml', 'models');
Doctrine_Core::createTablesFromModels('models');

schema.yml contains your table definitions in YAML format.

As you are already talking about frameworks, you might have a look at Symfony which does pretty much the things you want and which provides an even easier interface for it (than Doctrine itself). You can either use Propel or Doctrine as ORM.