Jump to content

Insert query containing mediumblob


christh

Recommended Posts

Hi forum members

 

I hope you can help me.

 

If I have a table that contains uploaded documents stored in a MediumBlob - can I move it/insert a MediumBlob field into another table in the same ways as I would and INT or VarChar?

 

I can download and view the documents without issue but I'd like to move certain records to another table using a Query/Insert INTO however the insert fails if I include the MediumBlob field within the query.

 

Everything is inserted if I drop the MediumBlob field which makes me suspect I need to treat this type of data in a different fashion or do I have an error else where? - I've spend 2 hours double checking my script and I can't spot a typo...

 

mysql_query ("INSERT INTO data_main  (date, name, telephone, location, status, email, fname, size, type, content ) 
VALUES
('$date','$name', '$telephone', '$location', '$stat', '$email', '$fname', '$size', '$type', '$content')");

 

content / $content is the MediumBlob field and is extracted and stored from a standard query 

 

$content=$row['content'];

 

I've used an echo statement to confirm that the data is stored in $content however it just won't insert - With it removed from the insert query the insert.

 

Hopefully my problem is easy enough to follow and thanks in advance.

 

Chris

Link to comment
https://forums.phpfreaks.com/topic/191886-insert-query-containing-mediumblob/
Share on other sites

It sure would be nice if you showed us the data that was causing your query to fail, but best guess is that it contains SQL special characters that should be escaped before being put into a query so that the syntax of the query is not broken.

Hi and thanks for getting back to me.

 

More than happy to post anything you feel would be helpful - what do you mean by data?  The actual contents of the table or the query that extracts the data from the table.

 

The mediumblob ($content) is an uploaded Word doc.

 

Sorry for being dim.

 

Chris

Hi again

 

Thanks for pointing me in the right direction and you were spot on - after reading up, if you want to insert binary data into a BLOB column it needs to be escaped.

 

I added the following to my initial query

 

$content=$row['content'];

$content = addslashes($content);

 

The insert query then worked.

 

Again thanks for your help.

 

Chris

Archived

This topic is now archived and is closed to further replies.

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