#!/usr/bin/perl -w

use DBI;
local($len);
$dbh = DBI->connect("DBI:mysql:nations", "randy", "") || die "Could not connect to db";
#$dbh->do("drop table images;"); # Keep existing data in the table
$dbh->do("create table images(fname char(130) unique, pic longblob);") || print "table already made ... that's OK\n";

for $filename (@ARGV)
{
	open(PICTURE, "<$filename") || die "Unable to open $filename";
	$len = sysread(PICTURE, $data, 99999999);
	print "Read " . length($data) . " bytes from $filename\n";
	$sth = $dbh->prepare("insert into images values (?, ?);") || die "Unable to prep statment";
	$sth->execute($filename, $data) || print "Unable to execute statement .. is the picture already loaded\n";
	close(PICTURE);
}
