HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [251]
3. Create a database according to the rules enforced by your system.
Sometimes, you can create the database within phpMyAdmin (as I did in the last section), but more often, you need to use a special tool like the one shown in Figure 1-15 to create your databases. Free Hostia imposes a couple of limits: The database name begins with the system username, and it can’t be more than 16 characters long.
Don’t freak out if your screen looks a little different than Figure 1-15. Different hosting companies have slightly different rules and systems, so things won’t be just like this, but they’ll probably be similar. If you get stuck, be sure to look at the hosting service’s Help system. You can also contact the support system. They’re usually glad to help, but they’re (understandably) much more helpful if you’ve paid for the hosting service. Even the free hosting systems offer some online support, but if you’re going to be serious, paying for online support is a good deal.
Figure 1-15: The database administration tool lets me create or edit databases.
4. Create a password for this database.
You probably need a password (and sometimes another username) for your databases to prevent unauthorized access to your data. Because the database is a different server than the Web server, it has its own security system. On Free Hostia, I must enter a password, and the system automatically creates a MySQL username with the same name as the database. Keep track of this information because you need it later when you write a program to work with this data.
5. Use phpMyAdmin to add tables to your database.
Once you’ve defined the database, you can usually use phpMyAdmin to manipulate the data. With Free Hostia, you can simply click a database name to log into phpMyAdmin as the administrator of that database. Figure 1-16 shows the new database in phpMyAdmin, ready for action.
Typically, a remote server doesn’t give you root access, so you don’t have to mess around with the whole root password mess described in the “Changing the root password” section of this chapter. Instead, you often either have one password you always use in phpMyAdmin or you have a different user and password for each database.
Figure 1-16: Now I can access the database in phpMyAdmin.
Making a Database with phpMyAdmin
When you’ve got a database, you can build a table. When you’ve defined a table, you can add data. When you’ve got data, you can look at it. Begin by building a table to handle the contact data described in the first section of this chapter, “Examining the Basic Structure of Data”:
1. Be sure you’re logged into phpMyAdmin.
The phpMyAdmin page should look something like Figure 1-17, with your database name available in the left column.
2. Activate the database by clicking the database name in the left column.
If the database is empty, an Add Table page, shown in Figure 1-18, appears.
3. Create a new table using the phpMyAdmin tool.
Now that you have a database, add the contacts table to it. The contacts database has four fields, so type a 4 into the box and let ’er rip. A form like Figure 1-19 appears.
4. Enter the field information.
Type the field names into the grid to create the table. It should look like Figure 1-20.
Figure 1-17: The main screen of the phpMyAdmin system.
Figure 1-18: Type a table name to begin adding a table.
Figure 1-19: Creating the contacts table.
In Figure 1-20, you can’t see it, but you can select the index of contactID as a primary key. Be sure to add this indicator. Also set the collation of the entire table to ascii_general_ci.
5. Click the Save button and watch the results.
phpMyAdmin automatically writes some SQL code for you and executes it. Figure 1-21 shows the code and the