Jump to content

Unescaping binary data from mysql blob column


perlmonger

Recommended Posts

I'm having difficulty getting usable binary data out of a mysql database. I'm uploading and storing a pdf file in a mediumblob column in mysql and then trying to serve it up to the browser. It's pretty obvious that the problem lies in the escaping and unescaping of the binary data. I've tried addslashes() and mysql_escape_string() to escape the data before storing and stripslashes() on retrieval to unescape but still get corrupted data. I'm using PHP 4.2.3 with magic quotes "ON" and magic quotes runtime "OFF". With magic quotes "on" I would think that I wouldn't have to use addslashes() or any kind of escaping but I can't insert the data without some escaping. I get a sql error since it finds a double-quote character in the binary data. It seems that magic quotes doesn't do exactly what I think it does. The PHP docs indicate that the slashes added by addslashes() are not actually stored in the database but only used to escape the data during insert and somehow discarded. That would be the desired behavior since one wouldn't have to remove them upon retrieval. Can someone help me figure out what I need to do here?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.