Home > Articles > Programming

  • Print
  • + Share This

Storing Your Bootstrap Content

People unfamiliar with databases think of them as something complex and mysterious. Nothing could be further from the truth. Think of a database as merely a technology that stores and retrieves data. Data is stored in tables and each table contains one or more records. All the tables together make up your database. To use a real-world analogy, a database is like one of the drawers in a file cabinet. Each drawer has several folders, which correspond to database tables. Each folder, in turn, has several pages inside, which correspond to the records in a table. That's all there is to it. If you can use a spreadsheet program, such as Microsoft Excel, you shouldn't have any problems using a database.

What makes a database powerful are the built in operations for quickly and efficiently storing data, modifying/deleting it, combining, and retrieving different views of data. You invoke these operations by communicating with a database in a language known as Structured Query Language (SQL). While it's beyond the scope of this article to cover databases and SQL in detail, an example should be sufficient to get you started creating the database for your personal Web business. There are three general steps:

  1. Create your database.

  2. Design the tables you need.

  3. Fill these tables with data.

As an example, let's do the three steps for our personal Web business based on hacker phrases. First we create a database, which we'll call hacker.mdb (not shown). Remember this name, because we'll use it later on when we do our scripts. The second step is to design the tables for this database. We need tables for the hacker phrases and also for the hacker dictionary. Let's just look at the table for the hacker phrases.

A hacker phrase consists of a phrase, a description of when to use that phrase, and an example of using that phrase (refer to the sample hacker phrase displayed in Figure 1). Thus, a database table that stores hacker phrases needs at least the following fields: phrase, usage, and example.

Let's call our table hackerphrase. The design of this table in Microsoft Access looks like Figure 4.

Figure 4 Database table design for a hacker phrase.

Each field (in the column labeled Field Name) has a specific Data Type. The phrase and usage fields are defined as Text data types, since the number of characters needed for a hacker phrase and to describe its usage are typically small. The example field, however, can be quite long, so it's defined as a Memo data type.

Notice in Figure 4 that, in addition to phrase, usage, and example fields, the table also has phraseID, votes, and total fields. You can ignore the votes and total fields for now. However, the phraseID field is important. Each hacker phrase is assigned a unique number (the phraseID), which we will later use to randomly select phrases from the table.

With the table created, the third and last step is to manually fill it in with bootstrap content. I added about 50 hacker phrases to the table (see Figure 5).

Figure 5 The hackerphrase table with bootstrap content filled in.

Upload your database to a directory or subdirectory in your Web server.

Important: Uploading the database to a subdirectory—whose name only you know—is much more secure than putting it in the same directory as your home page. If you put it in the same directory as your home page, people who guess the name of your database may be able to download it! However, to simplify the code we'll assume that the database is stored in the same directory as your home page.

Next, we look at how to get bootstrap content out of a database and into a Web page.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.