0

I am looking for a way to initial our application quickly with current database schema which is defined and seed data to the database in zendframework 2. This has been done quite well in the modern web framework like rails, play!, you name it but I don't know if it's existed in zf2. I don't find any official documentation about this :)

1 Answer 1

1

Use Phing for that task. Initializing (installing) your app, should not be done by the app itself but by an external agent like Phing.

Here is an example phing target of how you can install your database and populate it with initial data:

<target name="recreate-db">
    <echo message="[Data] Drop and recreate database..." />
    <pdosqlexec
            url="mysql:host=${db.project.host};dbname=${db.project.dbname}"
            userid="${db.project.username}"
            password="${db.project.password}"
            onerror="abort">
        DROP DATABASE IF EXISTS `${db.project.dbname}`;
        CREATE DATABASE `${db.project.dbname}`;
    </pdosqlexec>
    <echo message="[Data] Populate database with schema and start-data ..." />
    <pdosqlexec
            url="mysql:host=${db.project.host};dbname=${db.project.dbname}"
            userid="${db.project.username}"
            password="${db.project.password}"
            onerror="abort">
        <transaction src="${basePath}/db-versioning/schema.sql" />
        <transaction src="${basePath}/db-versioning/start-data.sql" />
    </pdosqlexec>
</target>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.