Extract files from a mysql database

Sham Prasad <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
Hi all,

I am new to this list and this is my first posting. Please correct if my
mail is not specific to the list.
I am working on bugzilla which has a mysql database called "bugs". It has a
table named "attachments" in it. All the bug attachments are stored in the
database in a zip format. what i am trying to do is, i want the attachment
to be extracted to my file system from the database and i am trying it
through a perl script using DBI and DBD::mysql modules.
I will give an example: there is a bug having bug_id 5626, it has a
attachment named 5626.zip. now my script should extract/copy this file(
5626.zip) to a drectory on the file system. The script which i have written
gets me the contents of the file only and not the file. But the content i
guess is stored in a binary format(BLOB) so i am not able to read anything
in the content. Below is my code

#!usr/lib/perl
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 sql query represents the contents of the file i
am trying to extract.
attach_id is the attachment id.
The above script gives me only the contents of the file but i want the file
itself to be extracted to the directory on the file system.

I searched in the google but didn't find any solution. But i got some info
that i can do it using DBI and DBD::mysql. so please can anyone help me out,
i want the files from the table to be copied to the file system how can i do
it using DBI and DBD::mysql?? what changes should i do in my script to make
it copy files from the database? "i am working on red hat enterprise linux
2"
Please mail me if you need more details.

Waiting for your reply
Sham
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.