hi monks,

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

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.