Votes: 4 bytes. Comments file: Binary file, variable
Votes: 4 bytes. Comments file: Binary file, variable length registers. Structure: name length (1 byte) + name + comment length (2 bytes) + comment Current poll: Binary file, fixed length registers. Pollname: 40 bytes. If we want to find which poll is the current poll, we can open the Current pollfile, read 40 bytes, and get the pollname. We can then get the question for the poll by sequentially searching the pollnamein the Pollfile. The same sequential search can be adopted to retrieve all the options. Voting only implies adding one to a selected option. Comments can be added by appending data to the comments file. However, deleting data is a difficult task. First, the data has to be deleted by marking a poll or an option with blanks in its pollname, and then building a packing process that will recreate the file by physically eliminating the logically deleted records. For more on advanced file structures see File Structures and Object Oriented Approaches in C++ from Addison-Wesley (ISBN 0-201874-01-6). A plain files based data model is really useful when dealing with large amounts of data or when very specific searches must be done over a big volume of information and the queries can’t really be adapted to SQL or XML related common queries. For example, search engines such as Google ( http://www.google.com/) use a data model based on plain files to maintain the repository of information that is collected from the Web. The extra time needed to design, code, and maintain the programs that manage this information is compensated with superb performance that is really specific to the application. Using a plain file based data model in PHP is easy since PHP has plenty of file manipulation functions such as flock(), fwrite(), fgets(), fputs(), fopen(), fclose(), fseek(), ftell(), unlink(), file_exists(), filesize(), and so on. These have been explained in Chapter 9. Relational Database Model This is the most common approach for web applications today. SQL statements are used to insert, delete, and update the data. The model is defined by an entity relationship diagram (ERD), where you indicate the entities used and the relationship between them. Then you can convert the ERD into a table structure and use this structure to establish table relationships. Let’s see how we can model our poll application using a relational database: Polls table: pollid integer(4) pollname varchar(40) question varchar(200) Options table: pollid integer(4) option varchar(80) votes integer(4) Comments table: pollid integer(4) comment text Page 530
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services