Insert blob data into mysql using MDB2 in php

523 views Asked by At

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

There are 1 answers

0
DGoodyear On

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')
       );