next up previous contents index
Next: MySQL and CGI Up: Perl DBI Previous: Installing Msql-Mysql-modules   Contents   Index

Testing Perl DBI

You can create a Perl program that will read messages from the table that we created. Here is some example program called that will do just this:


use DBI;

$dsn = "DBI:mysql:bob:localhost"; #data source name
$user_name = "bob"; # user name
$password = ""; # passwords are either blank or existing

$dbh = DBI->connect($dsn, $user_name, $password, { RaiseError => 1});

$count = 0;
$infoget = "SELECT * FROM messages";
$sth = $dbh->prepare ($infoget);
while(@info = $sth->fetchrow_array()) {
    ($num, $sender, $message) = @info;
    print "$num ($sender) - $message\n";

print "$count Message(s)\n";


To run and test this program first change the permissions to 755 (as explained in Section 4.6) then run the program:

bash$ ./
1 (admin) - Hello Bob, how are you?
1 Message(s)

Joseph Colton 2002-09-24