how to insert and read binary data into mysql
$dbh->disconnect();
mysql> create table test (data longblob);
Query OK, 0 rows affected (0.03 sec)
$dbh = sql_init({db => 'CMDB', host=>'localhost', user=>'cmdbuser'});
open (F, "wordfile.doc");
while () {
$data .= $_;
}
close F;
$sql = "insert into test (data) values (?)";
$sth = $dbh->prepare($sql);
$numrows = $sth->execute($data);
$sth->finish();
1;
# now read
$dbh = sql_init({db => 'CMDB', host=>'localhost', user=>'cmdbuser'});
$sql = "select data from test";
$sth = $dbh->prepare($sql);
$numrows = $sth->execute();
open OUT, ">ms.doc";
$ref = $sth->fetchrow_hashref;
$newdata = $$ref{'data'};
print OUT $newdata;
close OUT;
$sth->finish();
$dbh->disconnect();
http://www.james.rcpt.to/programs/mysql/blob/
Labels: binary data, mysql, perl binary

0 Comments:
Post a Comment
<< Home