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!)
July 27th, 1999, 03:56 PM
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.
July 27th, 1999, 10:48 PM
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.
July 27th, 1999, 10:50 PM
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.
February 6th, 2000, 09:34 PM
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
February 7th, 2000, 12:24 PM
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.