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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.