Sham Prasad wrote:
Hi all,

Hello,

I have a bugzilla database running on mysql. If you are aware of
bugzilla, it has a table called "attachments". what i am trying to do
is get the attachments of all the bugs having  attachment/s into a
directory.
for example there is a bug with a attachment named abc.zip. can i
extract this file to a directory on my filesystem? as you have
mentioned the files in mysql table are in BLOB fields. i have written
a script but am not able to copy the file to the filesystem instead i
am able to copy the contents which is not readable.
Contents of the script

#!usr/lib/perl

use strict;
use warnings;

use DBI;
my $dbh = 
DBI->connect("DBI:mysql:databse=Pbugs;host=appletest","root","deltazia",{'RaiseError"
=> 1});
my $sth = $dbh->prepare(select thedata from attachments where
attach_id=143") or die "can't prepare statement";
print"Query Results\n";
while(my @row = $sth->fetchrow_array()){
print"@row\n";
}
$sth->execute or die "can't execute statement";
$dbh->disconnect;
Note -  thedata in the query represents the contents of the file.
the above script prints the contents of the attachment in a binary
form which is nonreadable.
Actually i want the file completely to be copied to the file system.
how can i do it using DBI?

write @row to a file

perldoc -f open
perldoc -f binmode

Reply via email to