File Operations

Before I go into a specific example of an application, let me explain how accessing a flat-file database works in general. There are four operations that you might want to perform—reading a record, adding a record, deleting a record, and modifying a record. Let’s look at the steps required to perform each of these operations.

Retrieving Records from a Database

1.
Find some information that will allow you to identify the record or records you need to retrieve.
2.
Open the file in which the data is stored.
3.
Search through all the records in the file until you find the ones that match the information you’re looking for.
4.
Copy the data from the file into a data structure that can be accessed from within your program.

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.