Online Book Reader

Home Category

HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [252]

By Root 1347 0
new table.

Now, the left panel indicates that you’re in the xfd database, which has a table called Contact.

After you define a table, you can add data. Click Contact in the left column, and you see the screen for managing the contact table, as shown in Figure 1-22.

You can add data with the Insert tab, which gives a form like Figure 1-23, based on your table design.

After you add the record, choose Insert Another Row and click the Go button. Repeat until you’ve added all the contacts you want in your database.

After you add all the records you want to the database, you can use the Browse tab to see all the data in the table. Figure 1-24 shows my table after I added all my contacts to it and browsed.

Figure 1-20: Enter field data on this form.

Figure 1-21: phpMyAdmin created this mysterious code and built a table.

Figure 1-22: I’ve added the fields.

Figure 1-23: Adding a record to the table.

Figure 1-24: Viewing the table data in phpMyAdmin.

Chapter 2: Managing Data with SQL

In This Chapter

Working with SQL script files

Using AUTO_INCREMENT to build primary key values

Selecting a subset of fields

Displaying a subset of records

Modifying your data

Deleting records

Exporting your data


Although we tend to think of the Internet as a series of interconnected documents, the Web is increasingly about data. The HTML and XHTML languages are still used to manage Web documents, but the SQL (Structured Query Language) — the language of data — is becoming increasingly central. In this chapter, you discover how SQL is used to define a data structure, add data to a database, and modify that data.


Writing SQL Code by Hand

Although you can use phpMyAdmin to build databases, all it really does is write and execute SQL code for you. You should know how to write SQL code yourself for many reasons:

♦ It’s pretty easy. SQL isn’t terribly difficult (at least, to begin with — things do get involved later).Writing the code in SQL is probably easier for you to write than to creating the code in phpMyAdmin.

♦ You need to write code in your programs. You probably run your database from within PHP programs. You need to be able to write SQL commands from within your PHP code, and phpMyAdmin doesn’t help much with that job.

♦ You can’t trust computers. You should understand any code that has your name on it, even if you use a tool like phpMyAdmin to write the code. If your program breaks, you have to fix it eventually, so you really should know how it works.

♦ SQL scripts are portable. Moving an entire data structure to a new server is difficult, but if you have a script that creates and populates the database, that script is just an ASCII file. You can easily move a complete database (including the data) to a new machine.

♦ SQL scripts allow you to quickly rebuild a corrupted database. As you’re testing your system, you’ll commonly make mistakes that can harm your data structure. It’s very nice to have a script that you can use to quickly reset your data to some standard test state.

Understanding SQL syntax rules

SQL is a language (like XHTML, JavaScript, CSS, and PHP), so it has its own syntax rules. The rules and traditions of SQL are a bit unique because this language has a different purpose than more traditional programming languages:

♦ Keywords are in uppercase. Officially, SQL is not case-sensitive, but the tradition is to make all reserved words in uppercase and the names of all your custom elements camel-case (described in Book V, Chapter 6). Some variations of SQL are case-sensitive, so you’re safest assuming that they all are.

♦ One statement can take up more than one line in the editor. SQL statements aren’t usually difficult, but they can get long. Having one statement take up many lines in the editor is common.

♦ Logical lines end with semicolons. Like PHP and JavaScript, each statement in SQL ends with a semicolon.

♦ White space is ignored. DBMS systems don’t pay attention to spaces and carriage returns, so you can (and should) use

Return Main Page Previous Page Next Page

®Online Book Reader