#!/usr/bin/perl -wT # show_banner.cgi use strict; use DBI; use CGI qw(:standard); use POSIX; use Image::Size qw(html_imgsize); my $dbname = 'book'; my $dbhost = 'localhost'; my $dsn = "DBI:mysql:database=$dbname;host=$dbhost"; my $dbh=DBI->connect($dsn,"user","password"); if (!defined($dbh)) { print header; print "\nerror: There is a problem connecting to the MySQL database:\n"; print DBI->errmsg; print "-" x 25; exit; } my $time = strftime("%Y-%m-%d %I:%M:%S", localtime); my $query = qq(select ID from image_tracker); my $sth = $dbh->prepare($query); $sth->execute; my @num; while (my $val = $sth->fetchrow_array) { push(@num, $val); } my $rand = int(rand(@num)); $query = "select IMAGE, URL, ALT from image_tracker where ID=" . $num[$rand]; $sth = $dbh->prepare($query); $sth->execute; my ($image, $url, $alt) = $sth->fetchrow_array; $query = qq(update image_tracker set IMPRESSIONS=IMPRESSIONS+1, LAST_IMPRESSION='$time' where IMAGE='$image'); $sth = $dbh->prepare($query); $sth->execute; $dbh->disconnect; my $size = html_imgsize($image); print qq($alt);