The DBI.pl Functions

To simplify coding we can take out of the previous program the most of the interfacing to mysql.
This leaves us free to concentrate on dealing with the data that mysql produces.

DBI.pl is a prewritten perl script that does this.

DBI.pl contains a number of useful functions

Take time to examine the script and to get a feel for what it does.

There is a copy of this script in the /home directory on cybil.

You should take a copy of DBI.pl and place it in the directory from which you intend to run your perl scripts.
(usually public_html/cgi-bin).

Here is the same example as above using some of the functions available from DBI.pl
(lastf/public_html/cgi-bin/sqlexample2.pl)

#!/usr/bin/perl

#Make the DBI.pl library of sql/perl functions available
  require "DBI.pl";
# assign the name of the table to be used
  $table_name="etrader";
# use function in DBI.pl to initialize database
  &initialize_dbi;
# use function in DBI.pl to run/execute mysql query as a parameter
  &run_statement("select * from $table_name;");
# html output
print "Content-type: text/html\n\n";
print "<h2>Testing the Perl/Mysql Interface</h2>";
print "Here is the contents of the Mysql database - etrader<p>";
# load contents of the record into the variables and print them
while (($date,$fname,$lname,$email,$description,$price)= $sth->fetchrow){
       print "$date,$fname,$lname,$email,$description,$price<br>";
}
exit;

Exercises
1. There is a procedure available from DBI.pl that could have been used in the code above.
Find it and replace the appropriate code with the procedure