I've been working on getting images into a MySQL database, and I think I'm doing things correctly, but wanted verification. I've seen the same thing done several different ways, so thought someone might have input.

I've been using the CGI.pm documentation, the DBD/DBI documentation, and a number of PM threads.

my $img = $query->upload('pc_img'); $img = <$img>; my $id = $query->param('pc_id'); my $sql = "INSERT INTO data_table (id, image) VALUES (?, ?); + ## id is BIGINT type, image is LONGBLOB type my $sth = $dbh->prepare($sql) or die "Couldn't prepare: $DBI::errstr\n +"; $sth->execute($id, $img) or die "Unable to execute query: $DBI::er +rstr\n"; $sth->finish; $dbh->disconnect;


I'm using MySQL AB's MySQLCC to view the contents of the database, and it shows there is indeed data in the 'image' field, and if I upload a GIF, it's GIF89a and then garbled text, and if it's a JPG, usually y0ya-garbage-garbage so I think binary data is being put into these BLOB type fields.

However, the problem is as follows: MySQLCC doesn't display GIFs, only supporting 'free' formats ( damn Unisys ) and when I try to open a JPG from the viewer, it says "An error occurred while opening this image."

So my dilemna is 'Am I doing it right?' and suffering from a limitation of the program? Am I doing it wrong? Is there another application out there that will allow me to connect to a database and show me information w/o me having to install something server-side like MySQLMan?

I'd really appreciate your input.
cidaris

In reply to Images into MySQL database by cidaris

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.