As far as how to do it, for binary or text you make a blob or text type field in mysql. The storage requirements and maximum size are listed as:
TINYBLOB, TINYTEXT L+1 bytes, where L < 2^8
BLOB, TEXT L+2 bytes, where L < 2^16
MEDIUMBLOB, MEDIUMTEXT L+3 bytes, where L < 2^24
LONGBLOB, LONGTEXT L+4 bytes, where L < 2^32
From the Mysql dev manual. As far as putting the file into it, just store the data in a string and do an insert:
my $file = <FILE>;
$dbh->do("insert into file_table set data = '$file'");
Of course using $dbh->do() is not the best way to accomplish this... but it's fast and to the point. I've used a database for storing files in one or two situations... it has to be just the right situation for it to be a good thing.
Something to take note of, and I mention it because it was something that bit me and took me a while to figure out why. Make sure that your
max_allowed_packet is set to a sufficiently high number on
both the client and server side if using mysql or else you'll have strange failures without much in the way of reasonable error codes to figure out why it was failing. I can't tell you what caveats there may be for other db's because I haven't used them, but for mysql, this one got me!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.