BLOB转换为字符串或图像/PHP或SQL [英] BLOB to String or image / PHP or sql

查看:156
本文介绍了BLOB转换为字符串或图像/PHP或SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,该数组在三维上为我提供了图像斑点.

I've an array that gives me an image blob in the 3rd dimension.

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

but I need the image, i tried with 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值:

without the expressions it works but i get that blob value again like in the standard array:

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

我可以知道如何在PHP或仅在SQL中转换该值吗?

May I know how to convert that value in PHP or only in SQL ??

推荐答案

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

use mysql query to get the blob data in a variable and then use this

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

这篇关于BLOB转换为字符串或图像/PHP或SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆