By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,784 Members | 1,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,784 IT Pros & Developers. It's quick & easy.

Help on Insert an Image to Mysql Database Using Perl

rajiv07
100+
P: 141
Hi to all,

We can store image in mysql using MEDIUMBLOG data type.I want to know how to insert or select and store an image data type using perl.

Is any idea Please

Thanks.
Regards

Rajivgandhi.
Jan 23 '08 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Hi to all,

We can store image in mysql using MEDIUMBLOG data type.I want to know how to insert or select and store an image data type using perl.

Is any idea Please

Thanks.
Regards

Rajivgandhi.
To interact with a database in Perl, you are going to have to use the DBI module.

Regards,

Jeff
Jan 23 '08 #2

rajiv07
100+
P: 141
To interact with a database in Perl, you are going to have to use the DBI module.

Regards,

Jeff
Thanks Jeff

But my doubt is how do store image data type in perl variable.

Let Me explain

I have table IMAGE has images are stored.I want to retrieve and print the image using perl.

My IMAGE table Structure

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE  `xone`.`image` (
  2.   `idimage` int(10) unsigned NOT NULL auto_increment,
  3.   `image` mediumblob NOT NULL,
  4.   PRIMARY KEY  (`idimage`)
  5. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
my query to select image from table

Expand|Select|Wrap|Line Numbers
  1. use DBI;
  2.  
  3.  my $dbh=DBI->connect('dbi:mysql:xone:localhost','root','');
  4.  
  5.  
  6.  my $select_img=$dbh->selectrow_hashref("select image from image where idimage=\'2\'");
  7.  
  8.  
  9.  print "Content-type:text/html\n\n";
  10.  
  11.  print $select_img->{image};

The output will display Some special char

Is any Idea Please

Thanks
Regards
Rajivgandhi.
Jan 24 '08 #3

rajiv07
100+
P: 141
Hi i got the point, actually the problem was in MIME HEADER.

print "content-type:text/html\n\n";

replace with

print "content-type:image/jpeg\n\n";

Now Its working.
Jan 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.