Using Databases

There are many types of databases. In this getting started guide, we’ll outline what you need to set up a popular free database so that other technologies (such as ASP.NET or PHP) can interact with it.

A popular free choice for webmasters is a type of database called MySQL. You can download the free version of MySQL here. It runs on both Windows and Linux. We also recommend that you download a reference manual here. Once you have the database downloaded and installed, you need to configure your web technology to link it to your website (for example, using ASP.NET or PHP). This is typically done with something known as a “connection string.” Essentially, this is a piece of data that specifies where your database is, what data you wish to access, and what username and password, if any, you are using. Connection strings vary greatly from database to database, but mostly only in syntax—the above concepts are universal across databases and technologies. For more on virtually every type of connection string, see an excellent free resource here.

As with ASP.NET or PHP, databases are generally server-side, meaning that they run on your web server. If you want your database to be part of a website visible to the world (as opposed to just an experimental site on your computer), you’ll need to set your database up with your web host. The procedure varies from host to host, but generally you’ll need to upload or configure some files and change your connection string to reflect the new location of your database.

It is also worth covering how data is stored in a database, and what technologies are often used to retrieve it. Almost all data is stored in tables, with columns, called “fields,” and rows, called “records.” A sample table might be named “People” with fields of “First_Name,” “Last_Name,” and “Date_of_Birth.” Each record in this table would have data for all three fields (though some fields can be set to be left blank in some cases, if necessary). Many records can exist in one table, all with the same fields.

To query, or retrieve, this data, a language called SQL (for Structured Query Language) is often used. There are many variants on SQL and it varies slightly database by database. A basic SQL statement though, might look something like this:

SELECT * FROM PEOPLE_TABLE WHERE FIRST_NAME = “JOHN”

As you might know, the * character means all, so this statement selects all of the records—each one represents a different person—from the table with all the people listed and shows or returns the record if the person’s first name is John. This is a very basic SQL query; they are usually much more complex, but you can get the general idea from this.