in reply to Working with DBI and BLOB
This is exactly the purpose behind using strict. Doing so, you would have found that you are placing the actual image data in $img_data, but are trying to put $image_file into the database. Switch either one of the variables and it should work fine.
update: I figured you could use a small rewrite. Some points I covered:
#!perl -w use strict; use DBI; use LWP::Simple; my $img_url = "http://weather.unisys.com/satellite/sat_ir_west.gif"; my $latest_img = "/usr/home/mhearse/weather_images/latest.gif"; my ($min, $hour, $day, $mon, $year) = (localtime())[1..5]; $year += 1900; my $img_name = "$mon-$day-$year-$hour:$min"; my $img_data = get($img_url); die("failed to fetch image from internet!\n"); unless ( defined($img_data) ); open( my $fh_latest, ( -e($latest_img) ? '+<' : '+>' ), $latest_img ) or die("could not open file: $!"); binmode($fh_latest); my $latest_data = do { local $/; <$fh_latest> }; if ($latest_data ne $img_data) { seek($fh_latest, 0, 0); truncate($fh_latest, 0); print $fh_latest $img_data; my $dbh = DBI->connect( 'dbi:mysql:weather_images', 'user', 'secret', { RaiseError => 1, AutoCommit => 1 } ); $dbh->do( 'INSERT INTO gw_ir (image_name, image_file) VALUES(?,?)', undef, $img_name, $img_data ); $dbh->disconnect(); warn("File was not current; updates made.\n"); } else { warn("File was current, no updates made.\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Working with DBI and BLOB
by mhearse (Chaplain) on Dec 24, 2004 at 21:46 UTC | |
by BUU (Prior) on Dec 25, 2004 at 19:37 UTC | |
|
Re^2: Working with DBI and BLOB
by mhearse (Chaplain) on Dec 24, 2004 at 21:52 UTC | |
by saskaqueer (Friar) on Dec 24, 2004 at 22:03 UTC |