A free and open-source book on ZF3 for beginners


16.3. Setting Up the Database

We will need to set up a sample "userdemo" database. The database will have a single table named user for storing data associated with users of our website (see figure 16.2 below).

Figure 16.2 User table Figure 16.2 User table

The user table contains the following fields:

In your own website, you will likely want to add more fields to the user table. In this sample, we only define some minimum set of fields.

You can create the user table with the following SQL statement:

CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(128) NOT NULL,
  `full_name` varchar(512) NOT NULL,
  `password` varchar(256) NOT NULL,
  `status` int(11) NOT NULL,
  `date_created` datetime NOT NULL,
  `pwd_reset_token` varchar(32) DEFAULT NULL,
  `pwd_reset_token_creation_date` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_idx` (`email`)
);

You can find a migration, which creates the user table, in the User Demo sample application.

If you are new to migrations, refer to chapter Database Migrations.


Top