#1
  1. No Profile Picture
    ebaum11
    Guest
    Devshed Newbie (0 - 499 posts)
    I'm trying to upload binary data and store it in mySQL as a mediumblob. Since there's always the possibility of quotes (along with any other character) within the binary stream, I assume I need to do something along the lines of AddSlashes to ensure that the sql request won't fail. The trouble is I'm finding that StripSlashes is blowing away the string when I retrieve it. I've tried rolling my own encoding, but ereg_replace("'", "'", $string) is truncating my data, apparantly at the first null character it hits.

    So: what's a solution for safely getting binary data into mysql via php? (And back out again!)

    Thanks.

    Eric
  2. #2
  3. No Profile Picture
    moderator
    Guest
    Devshed Newbie (0 - 499 posts)
    I don't know if it's an option, but I'd consider a work-around.

    First store the binary data in a file, then create a varchar field in the database that can store the path to that file.
  4. #3
  5. No Profile Picture
    chyrag
    Guest
    Devshed Newbie (0 - 499 posts)
    Yeah, the method which the moderator suggests also is less demanding on mysql. It seems BLOB storing/retrieval especially if they are huge in size, are quite CPU consuming. filenames on the other hand is quite cool.
  6. #4
  7. No Profile Picture
    chyrag
    Guest
    Devshed Newbie (0 - 499 posts)
    Yeah, the method which the moderator suggests also is less demanding on mysql. It seems BLOB storing/retrieval especially if they are huge in size, are quite CPU consuming. filenames on the other hand, with blobs in the files is quite cool; you may have to use the tempnam function to get the unique filenames.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Bremen
    Posts
    11
    Rep Power
    0
    I have spoken with Eric about this problem couse I have had the same a time ago. His sollution was simply to encode the binary string to base64 and to decode it later if needed. This works fine even if I don't know about the load this might cause. But if the image has to be in the DB this is a working way after all. Cya
  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    There is a common misconception that you need to stripslashes() when pulling a field from mysql that had addslashes() used when stored. THIS IS NOT THE CASE. addslashes() is used to escape characters. IOW, the string:

    I said, "NO!". would be changed to:
    I said, "NO!". so that when it is added to mysql the quotes don't get interpreted as a control character of the query. MySQL does not store the . So when it is pulled the original string is there sans the backslashes.

    The existence of stripslashes() is for other purposes, such as removing slashes added to strings passed via GPC when magic_quotes is on.

Similar Threads

  1. downloading binaries from MySQL
    By yoyolise in forum PHP Development
    Replies: 1
    Last Post: February 8th, 2004, 06:09 AM
  2. Extract image from MySql to display on page
    By PHPme in forum PHP Development
    Replies: 6
    Last Post: January 30th, 2004, 05:06 PM

IMN logo majestic logo threadwatch logo seochat tools logo