Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic "update" vs "insert" blob question

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
I am trying to load grahpics into a blob in my database. All the examples I've found use "INSERT" to do it. Since I already have a record created shouldn't I use "UPDATE?" I'm not sure I understand the difference. I think "INSERT" creates a new row, correct? Also, it appears there is nothing special about puting a graphic into a blob and can be done like any other peice of data:

update table mytable set myblob='<a very long string of data that is an entire jpg file>' where something='some value';

Is that correct?

Also, I'm having trouble figuring out the max size of a "mediumblob" from the documentation.

TIA.
 
I'm sure it's possible to load binary data using an escaped string, but I've never managed/bothered to figure it out. What I do is save the binary data to a file on the server, then use the LOAD_FILE function to read it in.

A mediumblob has a maximum length of 2^24-1, 16777215 bytes; see TFM at .
 
I upload binary information into a database, but I encode it first. The files I deal with are not very large (50KB or less, and not a whole lot of files.)

In PHP I used base64_encode() before storing it in the database and base64_decode() after retrieval before serving it to the client. This might not be a good solution depending on what you are doing however because of the processor usage.

I haven't tried to store the binary data directly in the database myself. I don't see why it wouldn't work, but if you are using php and getting from a form make sure you check get_magic_quotes_gpc() and use addslashes() if necessary.

If the record exists already then use the UPDATE statement with a properly escaped string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top