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: http://lists.mysql.com/cgi-ez/ezmlm-cgi/1/8775 >.
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=5244 5EF3 B0B1 3826 E4EC 8058 7B31 3AD7
|• BLOB||LSzijarto||5 Oct|
| • Re: BLOB||Martin Ramsch||7 Oct|