BLOB to String或image / PHP或sql

时间:2015-01-22 11:43:48

标签: php mysql sql

我有一个数组,它在第三维中给我一个图像blob。

但我需要图像,我尝试使用SQL

<?php $global = \Database::getInstance()->execute('SELECT CONVERT(VarChar(40), image)
    FROM mm_product2 
    WHERE id = '.$referenzen['id'])->fetchAllAssoc(); ?>
<?php print_r($global);?>

显示此错误:

Fatal error: Uncaught exception Exception with message Query error:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'VarChar(40),
image) FROM mm_product2 WHERE id = 23' at line 1 (SELECT CONVERT(VarChar(40), 
image) FROM mm_product2 WHERE id = 23

没有表达它可以工作,但我再次获得blob值,就像在标准数组中一样:

[image] => 85392c33-a0f7-11e4-acb9-08606e695836 ) 

我是否知道如何在PHP中转换该值或仅在SQL中转换

1 个答案:

答案 0 :(得分:4)

使用mysql查询获取变量中的blob数据,然后使用此

'<img src="data:image/jpeg;base64,' . base64_encode($image) . '" width="200" height="200">'