Database Component Design Alex Kossey 1. Overview The database component consists of a single PHP file that provides functions for interacting with the MySQL database. Originally, the plan was to provide a PHP file that replaced all MySQL queries with essentially equivalent PHP functions. However, the database component as it stands now provides more abstract functionality: it provides functions for wiping the whole database, inserting votes, retrieving all the election data, etc. The database that resides in the MySQL database consists of three separate tables: one to keep track of the types of each question on the ballot (for easy access by the data visualization component), one to keep track of which students have already voted, and one to keep track of the responses of the ballot. Note that although inserting a vote involves recording the name of the voter in the "already voted" database, the name of the voter and the voter's response are stored in completely different locations and thus aren't connected with each other after the vote is placed. 2. Interface The database component consists basically of seven functions in the DatabaseInterface.php file: db_wipeDatabase, db_connect, db_createTable, db_insertIntoTable, db_insertVote, db_getQuestionTypes, and db_getCurrentElecResults. The first four of these functions are only called by the Server Initialization component. The Election Administration component inserts information into the database with db_insertVote. The Data Visualization and exporting component retrieves the necessary information from the database with the final two functions. 3. Function Descriptions Descriptions of the functions themselves appear in the comments to the DatabaseInterface.php file; these descriptions basically paraphrase the ones in the file. db_connect: Takes the database server name, username, and password (constants in a constants file) and connects to the appropriate database in the MySQL database. db_wipeDatabase: Clears the database so that a new election can be stored. Just deletes all three of the tables so that they can be recreated when a new election begins. db_createTable: Takes a name of a table and an array specifying information about all the columns that should go in the table. Creates this new table based on the information given in the array. This array itself contains arrays holding columns names, column types, and column sizes so that the table can be appropriately formatted. db_insertIntoTable: Takes a table name and an array of values to insert into columns of a row in that table. Inserts this information into a row of the given table. db_insertVote: Takes a voter name and an array of voting info (an array mapping ballot question names to ballot question answers). Checks in the voter table to check if this voter has already voted. If so, they cannot vote again. Otherwise, it uses db_insertIntoTable to insert the voting information into the database. db_getQuestionTypes: Returns an array mapping question name to question type (just takes the contents of the question types table and returns them). db_getCurrentElecResults: Returns the current results of the election as a two-dimensional array. Each row in the two-dimensional array is an array consisting of one voter's responses to the ballot questions, so each row is a mapping from ballot question to voter response.