#!/usr/bin/perl
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);
$sth->execute();
while(@info = $sth->fetchrow_array()) {
($num, $sender, $message) = @info;
print "$num ($sender) - $message\n";
$count++;
}
print "$count Message(s)\n";
exit;
To run and test this program first change the permissions to 755 (as explained in Section 4.6) then run the program:
bash$ ./dbitest.pl 1 (admin) - Hello Bob, how are you? 1 Message(s)