1 Feb 2006 08:27
Extract files from a mysql database
Sham Prasad <sham.ts <at> gmail.com>
2006-02-01 07:27:24 GMT
2006-02-01 07:27:24 GMT
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 <at> row = $sth->fetchrow_array()){
print" <at> row\n";
}
$sth->execute or die "can't execute statement";
$dbh->disconnect;
(Continue reading)
RSS Feed