List:General Discussion« Previous MessageNext Message »
From:Daniel Koch Date:July 29 1999 6:20pm
Subject:Re: BLOB objects & Perl
View as plain text  
"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/


Thread
BLOB objects & PerlPavel P. Zabortsev29 Jul
  • Re: BLOB objects & PerlPaul DuBois29 Jul
  • Re: BLOB objects & PerlDaniel Koch29 Jul
Re: BLOB objects & PerlPavel P. Zabortsev30 Jul