Database Introduction

The database is the single entity where all the data you’re working with is stored. It’s a lot like a spreadsheet file in how it organizes information.

A database can have many tables, which can be related in different ways. A table houses many records.

A table is akin to a sheet in a spreadsheet, and like any other table of data you’ve ever seen, it has rows and columns.

A record is a group of related values; it usually has a value that corresponds to every field in the table. This is analogous to a single row in a spreadsheet.

A field in a database is the column in a spreadsheet. It is the “title” for a single piece of information in a record. A data value is like a single cell: it’s the intersection of a record and a field.

Here’s a database with several tables. The table we’re looking at right now has three fields: ID, First Name, Last Name, and Occupation. It has four records: one for each person. Every cell in this table is a data value.


MySQL Introduction

MySQL is a database management system, and while there are other systems available, there’s no doubt that MySQL is the top banana, at least as far as the number of users goes. MySQL uses SQL (Structured Query Language) to build databases and work with the data inside them. As we’ve installed WAMP, we’ve installed phpMyAdmin, which is a decent user interface for building databases, so we’ll be using that to build our database.

Find the phpMyAdmin link, click that, and you should see something like this:

Click on Database. There’s a lot here that we won’t be discussing at all. Right now, just type “php_book” in the textbox under Create new database; then click Create:

Great! You’ve created your first database. Now click on php_book from left sidebar. There are interesting bits of information on the next screen: First, notice the left sidebar: it has the text “php_book (0)”; this tells us that the database php_book currently has 0 tables. Second, see that green bar near the top that said, “Database php_book has been created”

At the bottom, we can create a table in our php_book database. We’ll give it the name characters (as in, the characters in a story, not in a string), and type 4 in the Number of fields textbox. Hit Go.

Now you’ll see a table with empty text boxes and drop-down menus. This is where we defined the properties of the four fields that we said our table should have

Each row in this table corresponds to a field in our database table.

  • The first column is for the field titles, and you can see, I’ve set them up to match our example table image above.
  • The next column is the data type. The default is VARCHAR, which stands for variable character. Basically, VARCHAR is the data type for strings.
  • For the id field, we’ll change the type to INT: the ideal data type for integers, or whole numbers.
  • The rest of the fields will stay at the default of VARCHAR. As you can see, we choose 100 characters in the third column.
  • The fourth column is titled Default: it lets us define what the default value for these fields should be. The default default (ha!) is None, which means the field will be left blank, and we won’t change that.

Click Save at the bottom, and you should see an overview of our newly-created table:

Now, let’s insert a record or two. Up near the top, click the Insert tab. You’ll see forms for two records; so, fill ’em out!

After clicking Go, you’ll get some confirmation. Head up to the Browse tab and click that. You should see the data that we’ve added to our table.

comments powered by Disqus