0

Can anybody help me to insert blob data in Mysql using MDB2 through php ?

I want to insert file into database using MDB2.

MBD2 setup is works fine.

1 Answer 1

1

This may help, as I had trouble with this for anyone in the future, note the quote sets the 'blob' type when sprintf injected each string generated by the quote functions. The key part appears to be using "file://" with a reference to a file for it to work this way.

$database is a mdb2 object as typically given in other examples online.

// NOTE BELOW: The quote function or lower layers - requires the file reference as below // I could not pass the raw bytes through that were in a variable for some reason, as the // quote method appeared to modify the bytes - maybe as it assumes a charset?

$sql = 'UPDATE %s SET %s=%s WHERE iconid=%d';
$sql = sprintf ($sql,
         $database->quoteIdentifier('chanicon'),
         $database->quoteIdentifier('icondata'),
         $database->quote("file://".$_FILES['userfile']['tmp_name'][0], 'blob'),
         $database->quote($_REQUEST['iconid'], 'integer')
       );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.