problem uploading pictures o mysql database

Sebastian Reinhardt <[email protected]> Fri, 14 May 2010 13:02:06 +0200
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
Hello,

In one of my perl cgi scipts, I try to realize an upload to store some
pictures and description in an mysql database.
The text upload is working, but with some picture data I get trouble.
Here is the code snippet, which should upload the picture data:
-------------------------------------------------------------------------------------------------
my $sql_stmnt = 'UPDATE `offers`.`preowned` SET `pic0` =qw(';
while(read $picture,$data,1024)
      {
              $sql_stmnt .= $data;
      }
$sql_stmnt .= ') WHERE `preowned`.`Ref_nr` ='.$refnr;
print "sql_stmnt:",$sql_stmnt,"<br>\n"; # for debugging only
$sth = $dbh->prepare($sql_stmnt);
print "sql_status:",$sth->err(),":",$sth->errstr(),"<br\n"; # for
debugging only
$sth->execute();
-------------------------------------------------------------------------------------------------
So I have an sample picture as *.gif an d*.jpg. Uploading the gif is no
problem (only for this special gif- file!), but uploading the same
picutre as jpg is not possible. This is because in jpg- code some ' and
" signs are included! So how can I tell mysql, that these are binary
and  no mysql- related signs? I tried also an "BIN()" arounbd the
picture data, but without success.

Output for gif- upload:
----------------------------------------------
pic_size:1
pic_size:7
pic_size:GIF
sql_stmnt:UPDATE `offers`.`preowned` SET `pic0`
="GIF89a���������!�Created with GIMP�,���������;" WHERE
`preowned`.`Ref_nr` =2147483647
sql_status::

----------------------------------------------

Output for same file as jpg:
----------------------------------------------
pic_size:1
pic_size:7
pic_size:JPG
sql_stmnt:UPDATE `offers`.`preowned` SET `pic0`
="�����JFIF��H�H�����Created with GIMP���C����C�����"���������������������������������������������������������
������������������������?������" WHERE `preowned`.`Ref_nr`
=2147483647
sql_status:1064:You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '' at line 1
----------------------------------------------

Every entry is referenced by "Ref_nr". This number is an timestamp and
so every entry can identified by this number.

-- 
Kind regaards

Sebastian Reinhardt



-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]