arunvelusamy has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inserting picture into blob
by marto (Cardinal) on Nov 14, 2005 at 15:06 UTC | |
|
Re: Inserting picture into blob
by zentara (Cardinal) on Nov 14, 2005 at 17:33 UTC | |
|
Re: Inserting picture into blob
by cowboy (Friar) on Nov 14, 2005 at 22:27 UTC |