Connecting Tech Pros Worldwide Help | Site Map

Read blob from mysql

Thierry
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello,

I do have a mysql database with a BLOB column. What is the proprest way
to read this column ?

Thx,
Thierry

Michael Fuhr
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Read blob from mysql


Thierry <thierry_at_iceprod.com@no_spam_please.com> writes:
[color=blue]
> I do have a mysql database with a BLOB column. What is the proprest way
> to read this column ?[/color]

SELECT it just like any other field. Some people mistakenly say
to use stripslashes() on the result, but it's almost always wrong
to do so.

Are you having trouble working with binary data? If so then please
elaborate.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Randell D.
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Read blob from mysql


Michael Fuhr wrote:[color=blue]
> Thierry <thierry_at_iceprod.com@no_spam_please.com> writes:
>
>[color=green]
>>I do have a mysql database with a BLOB column. What is the proprest way
>>to read this column ?[/color]
>
>
> SELECT it just like any other field. Some people mistakenly say
> to use stripslashes() on the result, but it's almost always wrong
> to do so.
>
> Are you having trouble working with binary data? If so then please
> elaborate.
>[/color]

Question for Michael (since I am not the original poster): Why would
performing a stripslashes() on the result be *almost* always wrong on a
BLOB column? I could see where this might be suggested for binary data,
but not for ascii text... I'm just curious since I store data in BLOBs
(and read them back using SELECT) and I'm wondering if there is
something that I am (or am not considering) that I may not know about...

thanks
randelld
Michael Fuhr
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Read blob from mysql


"Randell D." <please.post.and.share@news.group.com> writes:
[color=blue]
> Michael Fuhr wrote:[color=green]
> > Thierry <thierry_at_iceprod.com@no_spam_please.com> writes:
> >[color=darkred]
> >>I do have a mysql database with a BLOB column. What is the proprest way
> >>to read this column ?[/color]
> >
> > SELECT it just like any other field. Some people mistakenly say
> > to use stripslashes() on the result, but it's almost always wrong
> > to do so.
> >
> > Are you having trouble working with binary data? If so then please
> > elaborate.[/color]
>
> Question for Michael (since I am not the original poster): Why would
> performing a stripslashes() on the result be *almost* always wrong on a
> BLOB column? I could see where this might be suggested for binary data,
> but not for ascii text... I'm just curious since I store data in BLOBs
> (and read them back using SELECT) and I'm wondering if there is
> something that I am (or am not considering) that I may not know about...[/color]

I said "almost always wrong" because I could contrive a situation
where calling stripslashes() on retrieved data would be appropriate.
For example, if magic_quotes_gpc is turn on but a script doesn't
check it with get_magic_quotes_gpc() and calls addslashes() or
mysql_escape_string() on form data anyway, then the form data would
be double-escaped. If the double-escaped data is inserted into a
database, then you'd need to call stripslashes() after retrieving
the data to get it back to its original format. Proper coding would
have avoided this, but if you're working on a project with other
programmers then you may not have control over how data is inserted
into the database.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Closed Thread