faqts : Computers : Databases : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

39 of 66 people (59%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

How can I load binary data as a blob using Perl

Feb 11th, 2008 01:03
dman, Ryan Parr, Peter Garner, http://sturly.com


Loading a blob from a MySQL database into a Perl program is the same as 
any other field.

i.e.

# Prepare the statement handle
my $sth = $dbh->prepare('SELECT filename,contents FROM test');

# Execute your statement
$sth->execute;

# Loop through the results
while(my($filename,$contents) = $sth->fetchrow_array) {
    # Save it to a file
    open O, ">$filename"; 
    binmode O;  # Only necessary on Windows, Unix treats it all the same
    print O $contents;
    close O;
}

$dbh->disconnect

__END__

If you had cmd.exe stored in the database for some reason, this would 
recreate it. More commonly though, if you were storing compiled 
documents such as PDF's or Excel files and serving it to a web page, 
this would be your answer.