"Pavel P. Zabortsev" wrote:
> Hello,
>
> How I can maintain BLOB objects (column) in MySQL 3.22.25 with Perl-5.005.3?
> How insert or select them?
>
> Yours sincerely,
> Pavel
I've posted this example script to the mailing list a few times in the past:
#!/usr/local/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect('DBI:mysql:test')
or die 'Could not connect to MySQL, stopped';
my $image;
{
local $/ = undef;
open IMG, 'test.gif'
or die "Could not open test.gif for read: $!, stopped";
$image = <IMG>;
close IMG;
}
my ($sql, $sth);
$dbh->do('drop table if exists image') or warn $dbh->errstr;
$sql = "create table image (filename char(20), image mediumblob)";
$dbh->do($sql) or warn $dbh->errstr;
$sql = "insert into image (filename, image) values (?, ?)";
$dbh->do($sql, undef, 'test.gif', $image) or warn $dbh->errstr;
open COPY, ">copy_of_test.gif"
or die "Could not create copy_of_test.gif: $!, stopped";
$sql = "select image from image where filename = ?";
$sth = $dbh->prepare($sql);
$sth->execute('test.gif') or warn $dbh->errstr;
my ($image_copy) = $sth->fetchrow_array;
$sth->finish;
print COPY $image_copy;
close COPY;
$dbh->disconnect;
__END__
--
Dan Koch
Webmaster
American City Business Journals
http://www.amcity.com/