#! /usr/local/bin/perl # Database Dumper: Solution # # Begin loading the needed extensions # use CGI qw (:html2); # The CGI extension use CGI::Carp qw (carpout); # The extra carping routine use DBI; # The DBI extension # # The file dbtype.pl sets a variable which determines the type of database # you will use. This file will be found in either /tmp or /temp. # use lib qw(/tmp /temp); require 'dbtype.pl'; # # Set the path, unbuffer STDOUT, and redirect errors to the browser # $ENV{PATH} = join ":", qw(/usr/bin /bin /sbin /usr/sbin /etc); $| = 1; carpout(\*STDOUT); # # Declare variables # my( $q, $dbname, $dbh, $sth ); # # Accept the CGI request # $q = new CGI; # # Read values from the form which called us # $dbname = $q->param("db_name"); # # Send the HTTP header # print $q->header; # # Set the and send <BODY> # print start_html("Simple Program"); # # Print out a nice big header, # print h1("Dump of database ${dbname}'s title table"); # # Try to connect to the database # $dbh = DBI->connect("DBI:$DB_type:test_nile", $DB_login, $DB_password); # # Prepare the following SQL statement and receive a statement handle # $sth = $dbh->prepare(q{SELECT * FROM title}); # # Execute the prepared SQL statement # $sth->execute; # # HTML to make the columns all line up properly # print pre; # # Routine to dump the contents of the rows previously SELECT'ed # DBI::dump_results($sth, 100); # # We're done with this statement, free up the resources # $sth->finish; # # Disconnect from the database, we're done! # $dbh->disconnect; # # Send </BODY></HTML> # print end_html; exit 0;