The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
php, mySQL, and binary data
Discuss php, mySQL, and binary data in the PHP Development forum on Dev Shed. php, mySQL, and binary data PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 9th, 1999, 07:00 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
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
|

July 27th, 1999, 02:56 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
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, 09:48 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
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, 09:50 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
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, 08:34 PM
|
|
Junior Member
|
|
Join Date: Feb 2000
Location: Bremen
Posts: 11
Time spent in forums: < 1 sec
Reputation 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
|

February 7th, 2000, 11:24 AM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|