Thanks for the replies! (Especially you, Dean :)
I finally got it to work. YAY!
Here's the code that worked if anyone is interested:
#! /usr/bin/perl -wT
use CGI;
use DBI;
use CGI::Carp qw(fatalsToBrowser);
$dbh = DBI->connect("DBI:mysql:mydatabase", "username", "password") || die
$DBI::errstr;
$graphsql = "SELECT loc_id, date, elevation FROM mrddaily WHERE loc_id = 1 AND date <=
20010228 AND date >= 20010101";
$sth = $dbh->prepare("$graphsql");
$sth->execute;
$ycount = 0;
$xcount = 0;
while (@ary = $sth->fetchrow_array()) {
if ($ary[0] == 1) {
push (@x, $ary[1]);
$xcount++;
push (@y, $ary[2]);
$ycount++;
}
}
$sth->finish();
$rc = $dbh->disconnect;
$dbh = DBI->connect('dbi:Chart:') || die "Cannot connect\n";
$dbh->do('CREATE TABLE line (date DATE, elevation FLOAT)');
$sth = $dbh->prepare('INSERT INTO line VALUES( ?, ?)');
for ($i=0, $j=0; $i<$xcount, $j<$ycount; $i++, $j++) {
$sth->execute($x[$i], $y[$j]);
}
$rsth = $dbh->prepare(
"SELECT LINEGRAPH FROM line
WHERE WIDTH=600
AND HEIGHT=400
AND X-AXIS=\'Date\'
AND Y-AXIS=\'Elevation\'
AND TITLE=\'Choke Canyon Elevation\'
AND COLOR=(red)
AND SHOWPOINTS=1
AND SHOWGRID=0
AND SHAPE=(fillcircle)
AND BACKGROUND=white
AND X-ORIENT=\'VERTICAL\'");
$rsth->execute;
$rsth->bind_col(1, \$buf);
$rsth->fetch;
print "Content-type: img/png\n\n";
print "$buf";