No local MySQL but with DBI and SQLite this works:

#!/usr/bin/perl -w use strict; use DBI; use MIME::Base64; my $dbh = DBI->connect('DBI:SQLite:dbname=test_blob.db', '', ''); $dbh->do('CREATE TABLE test_blob( a text , b text , Bindata BLOB )'); my $bindata = "ABC" . qq|\x00| . "DEF"; #added $bindata = encode_base64($bindata); my $sth1 = $dbh->prepare('INSERT INTO test_blob VALUES(?,?,?)' ); my @ar = qw|foo doog|; $sth1->execute(@ar, $bindata); my $sth2 = $dbh->prepare('SELECT Bindata FROM test_blob'); $sth2->execute(); my $row = $sth2->fetch(); my $fetched_data = $row->[0]; $sth2->finish(); $dbh->disconnect; print decode_base64($fetched_data); 1;

And from the database:

.schema test_blob CREATE TABLE test_blob( a text , b text , Bindata BLOB ); sqlite> select * from test_blob; foo|doog|QUJDAERFRg==

That code you posted had all sorts of other problems so I grabbed the above from a previous post. Update: Come to think of it, you could replace that SQL creation code with something like:

perl -e "$lf = @ARGV;$sql= 'insert into BLAH (' . eval{join ',',@ARGV +} . ') VALUES (' . eval{join ',', split//,'?' x $lf} . ')'; print $sq +l;" DOGS CATS FISH ANIMALS TRIKES KITES insert into BLAH (DOGS,CATS,FISH,ANIMALS,TRIKES,KITES) VALUES (?,?,?,? +,?,?)

Celebrate Intellectual Diversity


In reply to Re: array as mysql db rows by InfiniteSilence
in thread array as mysql db rows by tcf03

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.