CSCI A348/548
Lecture Notes Twenty-Eight

Fall 2000


Database access over the web.
We started with a discussion on designing a database for amazon.com and we used Harvey's work for that. We then went back to the lab notes and made a summary of mySQL database access from the command prompt of the monitor.

We said we wanted to do the same thing (access the database) through a program.

There are three options:
  • from Perl
  • from PHP
  • from Java

Today we will work with Perl. Let's start then from the simplest program:
burrowww.cs.indiana.edu% ls -l db*
-rw-r--r--   1 dgerman  students       42 Dec  2 12:40 dbCon
burrowww.cs.indiana.edu% chmod 700 dbCon
burrowww.cs.indiana.edu% ls -l dbCon
-rwx------   1 dgerman  students       42 Dec  2 12:40 dbCon
burrowww.cs.indiana.edu% cat dbCon
#!/usr/bin/perl

print "Hello, world!\n"; burrowww.cs.indiana.edu% ./dbCon
Hello, world!
burrowww.cs.indiana.edu% 

Very good that was easy. What do we need to do to connect to a database?

A specialized module (DBI.pm) and a set of drivers for the database that we will be using (mySQL). So I modify my program as follows:
#!/usr/bin/perl

use DBI; 

print "Hello, world!\n"; 
Yes, then you run it, and expect the program to compile and run fine, although with no output at all. This proves that we have DBI.pm installed (like CGI.pm).

Let's check the drivers. OK, I am using this book, just so that you know,
... I have it too, and it looks very useful, ...

... and I read that I can make these changes:
burrowww.cs.indiana.edu% cat dbCon
#!/usr/bin/perl

use DBI;

my @drivers = DBI->available_drivers(); 

foreach my $driver (@drivers) {
    print "Driver: $driver\n"; 

}

burrowww.cs.indiana.edu% ./dbCon
Driver: ADO
Driver: ExampleP
Driver: Oracle
Driver: Proxy
Driver: mSQL
Driver: mysql
burrowww.cs.indiana.edu% 

I see you're using a method of the package to retrieve the drivers. Indeed.








Last updated on December 2, 2000, by Adrian German for A348/A548.