List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:October 7 1999 2:56am
Subject:Re: BLOB
View as plain text  
On Tue, 1999-10-05 12:22:06 -0400, Laszlo Szijarto wrote:
> I cannot figure out how to insert a binary BLOB object into the
> mysql database.

There are quite a few old articles on this subject.

Inserting binary data is identical to inserting normal text, except
that four special characters have to be escaped:
- replace the binary nul     character (ascii code  0) with: \0
- replace the quote      (") character (ascii code 34) with: \"
- replace the apostrophe (') character (ascii code 39) with: \'
- replace the backslash  (\) character (ascii code 92) with: \\

See chapter "7.1.1 Strings" of the MySQL Reference Manual.

This means, that you can't insert binary data as it is, but only in
the escaped form.

The MySQL APIs of most (or all) programming languages have special
functions do to this escaping for you:
- in C:    mysql_escape_string()
- in Perl: quote method,
           or use placeholders with do or execute methods.
- in PHP:  AddSlashes()

For a nice perl example see
<URL: >.

Martin Ramsch <m.ramsch@stripped> <URL: >
PGP KeyID=0xE8EF4F75 FiPr=5244 5EF3 B0B1 3826  E4EC 8058 7B31 3AD7
BLOBLSzijarto5 Oct
  • Re: BLOBMartin Ramsch7 Oct