You're right, that was sloppy. Here is a revision:
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_data | mediumblob | YES | | NULL | | +------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
#!/usr/bin/perl use strict; use LWP::Simple; use DBI; my $url = "http://weather.unisys.com/satellite/sat_ir_west.gif"; my $file = "/usr/home/mhearse/weather_images/sat_ir_west.gif"; my $newfile = "/usr/home/mhearse/weather_images/latest.gif"; my ($min, $hour, $day, $month, $year) = (localtime)[1,2,3,4,5]; my $image_name = "$month-$day-$year-$hour:$min"; getstore($url, $file); if (-s $file != -s $newfile) { rename $file, $newfile; my $image_data = getFile($newfile); my $dbh = DBI->connect("dbi:mysql:weather_images", "ser", "********") or die("Error! $!\nAborting"); my $sql = qq(INSERT INTO gw_ir (image_name, image_data) VALUES ("$image_name", "$image_data")); my $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; }
MySQL doesn't like the sql statement.
DBD::mysql::st execute failed: You have an error in your SQL syntax. +Check the manual that corresponds to your MySQL server version for th +e right syntax to use near 'ÀµÖ* íÆ. ³ô®´ØR{mþÒ:»Àºëö*·ì¶k¼½.àë·' at +line 3 at ./simple line 24. Error executing SQL statement! You have an error in your SQL syntax. +Check the manual that corresponds to your MySQL server version for th +e right syntax to use near 'ÀµÖ* íÆ. ³ô®´ØR{mþÒ:»Àºëö*·ì¶k¼½.àë·' at +line 3 at ./simple line 24.

In reply to Re^2: Working with DBI and BLOB by mhearse
in thread Working with DBI and BLOB by mhearse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.