in reply to Inserting binary data into MySQL
Here's a little demo that reads 1MB at a time, and inserts it into the DB using placeholders.
This should give you a decent starting place. I highly recommend reading the database tutorials here on PM (as well as the DBI documentation) if you're a little unsure of what placeholders do. After understanding them, you will quickly realize their usefulness.open my $fh, 'big-binary-data.file' or die "Couldn't open file: $!"; # prepares an SQL statement with data to be filled in later my $sql = "insert into table set chunk_num=?, data=?"; my $sth = $dbh->prepare($sql) or die "Couldn't prepare sql statement: +$!"; my $chunk_num = 0; my $chunk_size = 1024 * 1024; while ( read( $fh, my $buffer, $chunk_size ) ) { $chunk_num++; # executes the statement with the appropriate data filled in $sth->execute( $chunk_num, $buffer ) or die "Couldn't insert data: $!"; } $sth->finish;
blokhead
|
|---|