tags:

views:

33

answers:

3

Is there a tool or script that generates and syncs database out of PHP models, just the way like Django does it for Python?

I'm aware of tools that generate databases out of XML, YAML, etc... I don't want it. I want to write production code on PHP, describing models, then run "syncdb" and get the database, that is ready to work with described models.

A: 

I remember playing with http://redbeanphp.com/ a while ago. You'd create your classes in PHP, add relationships to them via class variables, and it would take care of creating the database and keeping it updated.

Fanis
A: 

There is no such thing as "PHP Models". There are various ways to describe a database model, but none of them are standardized, so it's not possible for such tool to exist.

There are, however, tools that generate database tables out of models in some frameworks. However, those are specific to the framework's models (usually written in xml or yaml, by the way).

And anyway, database design is usually a more complicated issue than just "making it work with models", so unless you have a rather verbose model (describing indexes, data types, relations etc.), a tool automatically generating tables wouldn't be useful in production.

Mewp
Well, of course there are several ways. I'm looking for a tool that would provide it's own way of describing, that i would agree with if i like how it works. And of course, this tool should provide a convinient way to describe data types, relations and indexes. Otherwise it would be pretty much useless.
Anton N
So, can we say, that PHP is just too clumsy for this task and that's why existing tools go for xml/yaml? Or is there another reason?
Anton N
@Anton N: PHP is a programming language, and models are generally declarative (at least the part of them that defines the database schema). So it's just easier to define them in a declarative language, like xml or yaml. As for tools, I don't know any, though many frameworks can do that (as noted in other answers).
Mewp
A: 

Yii framework has something similar, called Gii. It auto generates other stuff too and you can add your own custom generators.

More info here: http://www.yiiframework.com/doc/guide/topics.gii

vladykx