Search code examples
phpzend-framework2zend-db

automatically create db in Zend


I was wondering if Zend has any way to automatically construct a database from model declarations. I could not find any documentation on the matter. I'm talking now from the point of view of someone who has experience in Python, where both Django ORM and SQLAlchemy provide a way to automatically create all database tables by some simple introspection of the models. Is something like this available for Zend or do I have to manually create my database ?


Solution

  • You could install the Doctrine2 module for ZF2: https://github.com/doctrine/DoctrineModule

    You'll be forced to write entities in the Doctrine way, though. Once you created your entities you'll then have to use a console command to generate the SQL and inject the tables like so:

    orm:schema-tool:create
    

    Whenever you change something in your entities you then have to run:

    orm:schema-tool:update