Lab #9 - Databases and DBI
Create a table within a new database using the
DBD::SQLitedriver, using the same structure as for the sample customer table given in the lectures. You could use the code from the lecture as a starting point.Use the SQL
INSERTstatement to add some data to your table. Examine the SQLite database using thesqlite3command line utility, in order to verify that it worked. Run some generic SQL queries (eg.SELECT,UPDATE,DELETE) against the table and verify that they work as expected.Create another Perl program that retrieves all data from the customer table, sorting it by surname. Print the records out as text - perhaps you could format them using tabs or even fixed width formatting.
The previous program doesn't look anything a CGI. Add the standard Perl code to turn it into a CGI. You may also want to change your output so that it uses XHTML/CSS to format the output (eg. use a HTML table to layout the data). Make sure you use "
use CGI::Carp qw(fatalsToBrowser);" so that you can see any errors in your browser.See if you can create a FORM to collect information which your CGI will use to structure its query - eg. ask for a customer ID, surname, firstname and order value, then insert this data into the table. Try some different forms/queries.
Copyright © 2008-2009 Joel Sing
