use strict; use warnings; use dbh; use IO::File; my $dbh = (bless{},'main')->dbh('myweb'); $dbh->do(q( CREATE TABLE if not exists images( id int(32) auto_increment primary key, image text )CHARSET=Latin1 )); #print $dbh->selectrow_array('SHOW CREATE TABLE images'); # eine Grafik einlesen my $fh = IO::File->new; $fh->open('768.jpg', O_BINARY|O_RDONLY) or die $!; read($fh, my $image, -s $fh); $fh->close; # Grafik in MySQL Textfeld einfügen $dbh->do("INSERT INTO images(image)values(?)", {}, $image); # Grafik aus MySQL auslesen my $binary = $dbh->selectrow_array('SELECT image FROM images WHERE id = (SELECT LAST_INSERT_ID())'); # Grafik zur Kontrolle ausgeben $fh->open('new.jpg', O_CREAT|O_TRUNC|O_BINARY|O_RDWR) or die $!; $fh->print($binary); $fh->close; $dbh->do('drop table images');