Example code for storing picture in MySQL DB

--0003255549a260e2bb048bf1c943
Content-Type: text/plain; charset=ISO-8859-1

Anyone worked on a project where they have stored pictures in MySQL db from
Perl program? I need to store pictures in MYSQL and my initial thought was
a normal insert statement. Now I did a bit of search and people are making
it completed out there. I have not tried it, but I was thinking of grabbing
my picture and inserting into the table using a normal SQL insert like:

$dbh->do(qq{insert into mytable (id, pic) values(1,$pic_file_name)});


Any experience on this?

Regards

--0003255549a260e2bb048bf1c943--
Mimi Cafe [ Do, 22 Juli 2010 05:48 ] [ ID #2044974 ]

Re: Example code for storing picture in MySQL DB

2010/7/22 Mimi Cafe <mimicafe [at] googlemail.com>:
> Anyone worked on a project where they have stored pictures in MySQL db fr=
om
> Perl program? =A0I need to store pictures in MYSQL and my initial thought=
was
> a normal insert statement.

Nothing much about Perl, but the stuff related to Mysql itself. A referenc=
e:

http://forums.mysql.com/read.php?20,17671,27914#msg-27914

For myself I never wanted to insert picture into mysql, there are
other solutions instead.
How about MogileFS? http://danga.com/mogilefs/

--
Jeff Pang
http://home.arcor.de/pangj/

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Jeff Pang [ Do, 22 Juli 2010 05:58 ] [ ID #2044975 ]

Re: Example code for storing picture in MySQL DB

On Thursday 22 Jul 2010 06:48:08 Mimi Cafe wrote:
> Anyone worked on a project where they have stored pictures in MySQL db from
> Perl program? I need to store pictures in MYSQL and my initial thought was
> a normal insert statement. Now I did a bit of search and people are making
> it completed out there. I have not tried it, but I was thinking of grabbing
> my picture and inserting into the table using a normal SQL insert like:
>
> $dbh->do(qq{insert into mytable (id, pic) values(1,$pic_file_name)});
>

This suffers from a possible SQL injection:

* http://bobby-tables.com/

* http://community.livejournal.com/shlomif_tech/35301.html

Anyway, do you want to store the entire picture (as data) or just its
filename?

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shlomi Fish [ Do, 22 Juli 2010 09:17 ] [ ID #2044977 ]

Re: Example code for storing picture in MySQL DB

Mimi Cafe wrote:

> Anyone worked on a project where they have stored pictures in MySQL db from
> Perl program? I need to store pictures in MYSQL and my initial thought was
> a normal insert statement. Now I did a bit of search and people are making
> it completed out there. I have not tried it, but I was thinking of grabbing
> my picture and inserting into the table using a normal SQL insert like:
>
> $dbh->do(qq{insert into mytable (id, pic) values(1,$pic_file_name)});
>
>
> Any experience on this?

This is not clear: do you want to store the contents, or the (complete?)
file name?

The BIGBLOB type is fine for storing contents. These values are stored
outside the row data space, so need extra IO, and that is good.
You can process the blob in chunks to limit overhead.

To store the filename, use a VARCHAR(1000) with the proper CHARSET.

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
rvtol+usenet [ Do, 22 Juli 2010 08:51 ] [ ID #2044981 ]

RE: Example code for storing picture in MySQL DB

Years back I read the pros and cons of storing pictures in a database
(column type blob) against storing them on the file system, and I always
thought storing pictures in the database blob is a better option. But I have
never seen a clean example of how to programmatically insert the picture
(binary file) into the db table.

The example on MySQL forum is discussing using the use of MySQL Query
Browser to manually insert each picture into a database and that is not
possible when the large number of pictures is involved or when users are to
upload pictures using a web form.

http://forums.mysql.com/read.php?20,17671,27914#msg-27914


Today I found few PHP examples which are pretty what I was looking to do.

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uplo ading-files-to-m
ysql-database.aspx
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uplo ading-files-to-m
ysql-database.aspx


But then I came across this a compelling idea not to load pictures into
MySQL blob as it makes it difficult to manage when images are large and
especially not worthwhile when moving a large database to another server or
backup and restore in case of database failure. I will now store by pictures
in the file system and the file names in the database. Anyone interested
should read inserting pictures into MySQL database may want to first read
this page: http://hockinson.com/index.php?s=37


Cheers


=> -----Original Message-----
=> From: Dr.Ruud [mailto:rvtol+usenet [at] isolution.nl]
=> Sent: 22 July 2010 07:52
=> To: beginners [at] perl.org
=> Subject: Re: Example code for storing picture in MySQL DB
=>
=> Mimi Cafe wrote:
=> >
=> > $dbh->do(qq{insert into mytable (id, pic)
=> values(1,$pic_file_name)});
=> >
=> >
=> > Any experience on this?
=>
=> This is not clear: do you want to store the contents, or the
=> (complete?)
=> file name?
=>
=> The BIGBLOB type is fine for storing contents. These values are stored
=> outside the row data space, so need extra IO, and that is good.
=> You can process the blob in chunks to limit overhead.
=>
=> To store the filename, use a VARCHAR(1000) with the proper CHARSET.
=>
=> --
=> Ruud
=>
=> --
=> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
=> For additional commands, e-mail: beginners-help [at] perl.org
=> http://learn.perl.org/
=>



--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Mimi Cafe [ Do, 22 Juli 2010 16:53 ] [ ID #2044988 ]
Perl » gmane.comp.lang.perl.beginners » Example code for storing picture in MySQL DB

Vorheriges Thema: Word boundaries
Nächstes Thema: doubts in using net::telnet in perl