I am tring to insert a picture in to a blob type and the code doesnt work... Can you all help me... Thanks in advance...
#!/usr/bin/perl #A perl script to insert a blob into a database table #TABLE: create table blob_eg(sno integer not null auto_increment, pics + blob, primary key(sno)); #Module import use strict; use DBI; use diagnostics; #varible Declaration my $dbHandle; my $stmtHandle; my $pic; my $quoted_pic; #opening a picture open(my $fh, '/home/backup/old_docs/arun/pictures/1.jpg' ) or die $!; read( $fh, $pic, -s $fh ); $dbHandle=DBI->connect("dbi:mysql:tempdb","arun","password",{ RaiseErr +or=>1, AutoCommit=>0 }) or die ("cannot connect"); $quoted_pic = $dbHandle->quote($pic); $stmtHandle = $dbHandle->prepare( qq{Insert into blob_eg('pic') values +(?)}) or die("cannot prepare\n"); eval { $stmtHandle->execute($quoted_pic); }; if($@) { print "cannot execute. exception caught... $@"; $dbHandle->rollback(); }else { $stmtHandle->finish(); $dbHandle->disconnect(); print "Successfully inserted the pic into db"; } close($fh);
In reply to Inserting picture into blob by arunvelusamy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |