In this lesson we'll explain how to create a database in HP my admin.
First we need to define the purpose of our database so it puts things into context let's say for this
example we have a registration form on our hypothetical website that allows users to sign up to receive
our weekly newsletter The form would look something like this we'd have a first name the last name and
an email field also a submit button once the user clicks the submit button.
The form data will be processed using P HP and input it into our database
so the purpose of this exercise is to create the database that will store this information for each
registrant we'll create the form in each piece script later on our database will contain one table the
table will follow the same layout is 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 I.D. most database tables will have an I.D. 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've set the length of this number to three digits meaning it can not exceed nine hundred and ninety
nine if you expected your database to contain many more users.
You can increase the length to 10 or even 20.
Next we have the first name last name and email all of these are variable character data types abbreviated
to var chart.
This means they can hold letters and numbers we've set the length to a maximum of 50 characters.
Lastly we have the date field we'll set up this field so it records the date and time the user registered
on the system.
This is known as a timestamp and it's done automatically
to get started.
Click the home button.
That we will make sure we're both on the same screen next.
Click the database in the top menu
we'll call our sample database.
My website
and I generally like to avoid capital letters or spacing
and that's always a good practice when choosing names for databases and tables for the Coalition set
it to UTF UTF 8 Unicode c i this correlation is a set of rules for comparing characters in a character
set and UTF is widely used for its speed and accuracy so we generally like to use that now click Create
so you can see a message database was successfully created and we can see it on the left hand side.
Here my Web site.
So now click on the database name and now we'll go ahead and create the table that will contain our
data call the table users and for a number of columns type in 5 and click go.
Now we need to create our fields and define certain properties for each field we'll start with ideas
for the type.
Select integer the link 3 and this is the primary key so set the index to primary A.I. stands for auto
increment.
So make sure there's a checkmark in there.
Next is first name.
This is a bar chart and 50 character Max
last name.
Also bar Archer also 50 characters.
Same for EMA
and last date.
This is a timestamp
so remember this is going to record when the user registered for the newsletter and we don't have to
set up the link for a timestamp for default to select current timestamp
and that's it.
Now we can go ahead and proceed
and now we can see our table is created.