cd www
chmod 755 444.pl
http://cubist.cs.washington.edu/~cubist_logon/444.pl
#!/usr/bin/perl5 -w
use CGI;
use DBI;
First line says that this file should be executed using the binary perl5. It then needs to use the 'CGI' and 'DBI' libraries.
$html = new CGI;
print $html->header, "\n",
$html->start_html();
Next, it creates a new object of type CGI. This is your html page. First print its header (just by calling the 'header' function) and then some basic tags for the beginning of the page (just by calling start_html()).
print $html->end_html;
To properly terminate this HTML page, you need to call at the end the 'end_html()' function.
sub searchDatabase
{
$sql = "SELECT * FROM Elections2000";
$db = DBI->connect("dbi:Sybase:server=ISQL01", "cse444", "WeRock!");
$db or die "Sorry we couldn't connect!\n";
$sth = $db->prepare($sql);
$sth->execute();
$row = "";
while ($row = $sth->fetchrow_hashref()) {
$rec1 = $row->{lname};
print "Record 1 = $rec1<p>";
}
}
The query statement is clear. To connect to ISQL01, you call the "DBI->connect" function, with the parameters as above. You then need to call "prepare" and "execute". Finally, you retrieve row by row, by calling the "fetchrow_hashref()" function. To extract the record use "$row->{lname}". While this is missing from the code, there obviously is a "$row->{fname}".
http://cubist.cs.washington.edu/~cubist_logon/444_2.pl Input the word "Gore" (with proper capitalization). The script should return the "Gore" row. Check out the code it should be straightforward.