Let's make a table on localhost
.
The table will be called wombats, and will have these fields.
Field | Type | Special |
---|---|---|
wombat_id | INT | Primary key, auto increment, not null |
name | VARCHAR 50 | Not null |
weight | FLOAT | Nullable |
comments | TEXT | Nullable |
wombat_id
is an INT
, short for integer, that is, a whole number. It's the primary key of the table. Every wombat will have a different id, so even if two wombats have the same name, our programs can use the id to tell them apart.
wombat_id
will auto increment. As we add new records to the table, the DBMS will automatically make a new id value for them. One less thing for us to have to think about.
wombat_id
cannot be null. (We talked about null earlier.) "Not null" means the field is required. Every wombat record must have an id.
name
is VARCHAR
, meaning that it can hold a variable number of characters. Up to 50, for this field. It can't be null, that is, it's a required field for every record.
weight
is a FLOAT
. It's like a Single
in VBA, a number, like 2.1. It's nullable, meaning that it isn't required. If it's null, we don't know the weight of the wombat.
comments
is TEXT
. Anything you can type, up to 65,535 characters long. It can be null, so it's not required.
OK, start phpMyAdmin on localhost (ye olde CP Admin button, remember), and select the wombat DB.
On the Structure tab, tell phpMyAdmin that you want a table called wombats
, with four fields. Click the Go button to the right.
(That made me think of the bit from one of the TMNT movies: "Go ninja, go ninja, go!")
Now tell phpMyAdmin what fields you want.
Click the Save button. You'll see the structure of the table.
Adela
So we have a DB called wombats
, and a table called wombats
. Does every DB need a table with the same name?
No. Name the tables whatever makes sense. If we want to store data about wombats, then a table called wombats
makes sense.
Export DB to server
OK, we have a database on localhost
. Let's export what we have to the server.
Start phpMyAdmin on localhost
. With the wombats
DB selected, choose the Export tab.
Leave all the settings as is, and click the Go button (Go button, go button, go!). phpMyAdmin will make a file with the commands needed to recreate the table, and send it to your PC. Save the file somewhere.
(If you want, open the file in Notepad, and check it out.)
Now start phpMyAdmin on your server (from cPanel), and choose the wombats DB. Remember, it will be called rosie_wombats, or whatever your Linux username is.
Click the Import tab, click the Choose file button, and select the file you just saved.
Now click Go. phpMyAdmin will read the file, and run the SQL statements in it.
Look on the Structure tab, and the wombats table should be listed. Look at the table's structure, and you'll see the fields you created on localhost
.
W00t!
Up next
Let's add some records to the table.