Database Generation

Once you have valid ADM models defined, you can automatically generate a database for your project using ADM's database generation tool.

Please note that this tool is a part of the Cora demo project and not in the Framework core, so if you went the non-typical route and bypassed using the demo project as a base to build on, you'll need to grab the ADM.php file out of the demo project's root.

Create Your Database:

In order to take advantage of automated database creation, you need to make sure you've setup your database configuration. If you haven't done that yet, Click Here to view instructions on doing so. The other thing you'll need (as of me writing this), is command line access. In the future, an in-browser visual interface to the database creation tool may be added, but for now it's just a command line tool.

If on a shared hosting environment:
Because the database creation feature is a command line tool... what this means for people who will be hosting their app in a shared hosting environment without command line access is that you'll need to generate your database on your local machine and then use a tool (such as PhpMyAdmin) to export your generated database into an SQL file you can upload.

To automatically generate a database based on your model definitions you need to do the following:

  1. Open a Terminal.
    • If on a Mac, open your Applications, click the Utilities folder, and then select the "Terminal" application.
    • If on a PC, hit your Windows Key + R to open the "Run" window, then type in "cmd" and hit enter.
    • If on Linux you don't need me to tell you how to do this, but since I can't help myself I'll mention that Ubuntu and Mint both map the terminal to Ctrl+Alt+T.
  2. Navigate to your project's directory.
    • If you are XAMPP, MAMP, etc, that will likely be wherever you installed that and then in the "htdocs" folder within.
  3. Once at the root of your project, type "php ADM.php dbBuild" to have ADM build your database for you.
php ADM.php dbBuild
If you get an error about PHP not being a recognized command, that means PHP is not a part of your operating system's PATH. Google "add php to path" or something similar if you aren't sure how to do this.

If all went well, you should see a flurry of output to the console and your database should be ready to go!

Of course, if you want to read through the documentation in the Models page to fully understand how the mappings work for the purpose of setting your database(s) up manually, you can, although that takes more expertise and effort.

Empty a Database

So chances are you'll be making changes to your models throughout development and will need to rebuild your database each time. In order to make use of the automated creation tool again, you'll need to empty out any database(s) you're using by deleting all the existing tables. To speed up this process, the database generation tool also includes a command to delete all the existing tables.

This DELETES any data you have in the database. NEVER EVER use this on a live app. Use this only during development and know you will have to re-insert your test data afterwards.

To make this happen, you need to use the "dbEmpty" command and then specify a database connection from your project's database config file:

php ADM.php dbEmpty NameOfConnection

Automatic Data Loading

By default, when you run the "dbBuild" command, ADM will look for a file named "data.php" in the following directory:


If it finds a matching file, it will include it after it does the build. The expected use case is "data.php" uses Cora's database class to run some Insert commands to load data into the database for you. However, the file can do whatever you want, and you can use whatever tools you want within it (obviously). It's just a way for you to execute some code to populate your database with test data during development.

If you want to include a file other than "data.php", you can specify a different file after the build command like so:

php ADM.php dbBuild myfile.php