Chapter 11
Database Fundamentals
Goals

So far we have taught our Flash client to communicate with a server via XML. Our goal in doing this was to expose our Flash client to more data and allow that data to be dynamic. While housing data on the server is more dynamic than hardcoding it into our client, we are still not doing this the optimal way.

This chapter will temporarily take us away from both Flash and XML. We will begin a study of the third tier of a three tier web design; a database backend. In this chapter, we examine the fundamental principles and methods for using a relational database. Later chapters will than expand upon this knowledge, allowing us to create a database of questions which we will than relay back to the Flash client.

 

Background

We now have written a program that serves up one of twenty-four questions. These questions are written directly in the source code file. But what if we want to store an unlimited number of questions? What if we would like to let people add questions without having access to our source code? Maybe we even want to let players submit questions!

We need to store our questions in an external file of some kind.

Perhaps we could store them in a simple text file, and draw them out as needed. There are some major problems with this approach:

It’s going to be slow: the application will need to scan through and parse a lot of text to extract a particular question.

It’s going to require a lot of bandwidth: we will have to transfer the entire file and then dissect it. These problems tend to be exacerbated as the number of questions increases.

Many more problems arise as the number of simultaneous users increases, creating problems of contention for bandwidth and file access.

We are going to need to write the functions that read in and then parse the flat file. That will not be fun.

And we have to debug these functions. Even then, errors may occur in large scale use that we could never simulate in a test environment. Perhaps it crashes when the 65537th element is added because someplace we calculated an index using a 2-byte variable.