In this lesson we will explain how to create a database.
First, we need to define the purpose of our database so it put's things into context.
Let's say we have a registration form on our website that allows users to sign up to receive our weekly newsletter.
The form would have the following inputs:
Once users click the submit button the form data will be processed using PHP and inputted into our database.
So the purpose of this exercise is to create the database that will store this information for each registrant. (We will create the form and php script later on).
Our database will contain one table. The table will follow the same layout as the table in this illustration. The field names are on the left, and the properties of each field are on the right.
We start with an id. Most databases will have an id field that contains a unique auto-incrementing number that helps identify each record. This is known as a primary key. The data-type is integer, because we only want this field to hold numbers.
We have set the length of this number to three, meaning it cannot exceed 999. If you expected your database to contain many more users, you can increase the length to 10 or 20.
Next we have the firstname, lastname and email fields. All of these are variable character (VARCHAR) data-types. This means they can hold letters and numbers. We have set the length to a maximum of 50 characters.
Lastly we have the date field. We will set this field up so it records the date and time the user registered on the system. This is known as a timestamp, and is done automatically.
To get started, click the Home button to make sure you are on the home screen.
Your database has been created, and you should now see it in the left column.
Now click on the database name.
Next, we will create the table that will contain our data. Call the table users.
Insert 5 for columns and click go.
Now we need to create our fields and define certain properties.
Start with id:
Next is firstname:
Once you're finished click the "Save" button.
We can see our table has been created.