简体   繁体   中英

Insert blob data into mysql using MDB2 in php

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM