The script is primitive, as this is I am definetely a DBI amateur:mysql> describe gw_ir; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+----------------+ | image_id | int(11) | | PRI | NULL | auto_increment | | image_name | varchar(50) | YES | | NULL | | | image_file | mediumblob | YES | | NULL | | +------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
The main problem I'm having is with the storing the gif as BLOB. It doesn't seem to be working. Am I doing something obviously wrong? Also, I'm downloading the image every 60 minutes (it's only about 100k). Then comparing it to the previous to see if it is newer. Is there a better way to see if the image is current? I appreciate any help.use LWP::Simple; use DBI; $url = "http://weather.unisys.com/satellite/sat_ir_west.gif"; $file = "/usr/home/mhearse/weather_images/sat_ir_west.gif"; $newfile = "/usr/home/mhearse/weather_images/latest.gif"; ($min, $hour, $day, $month, $year) = (localtime)[1,2,3,4,5]; $image_name = "$month-$day-$year-$hour:$min"; getstore($url, $file); if (-s $file != -s $newfile) { rename $file, $newfile; $img_data = getFile($newfile); $dbh = DBI->connect("dbi:mysql:weather_images", "user", "********") or die("Error! $!\nAborting"); $sql = qq(INSERT INTO gw_ir (image_name, image_file) VALUES ("$image_name", "$image_file")); $sth = $dbh->prepare($sql); $sth->execute or die("\nError executing SQL statement! $DBI::errstr +"); $dbh->disconnect; } else { print "file is current\n"; } sub getFile { my($file) = @_; my $fh; unless (open $fh, "<", $file) { die "Error opening $file : $!\n"; } my $data; { local $/ = undef; $data = <$fh>; } close $fh; return $data; }
In reply to Working with DBI and BLOB by mhearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |