drjtua5953 2013-10-14 11:26
浏览 72
已采纳

从数据库读取或写入数据库

I try to show an image stored in a database. I wrote it with

$image = file_get_contents($testPfad);
$dateigroesse = filesize($testPfad);

$arrData = unpack("H*hex", $image); 
$data_string = "0x".$arrData['hex']; 

$sql = "INSERT INTO EHS.dbo.T_Signaturen (UnterschriftsDateiName,UnterschriftsBild,Dateigroesse,terminID) VALUES (
        '".$unterschriftsFileName."',
        CONVERT(varbinary(max),'$data_string'),
        '".$dateigroesse."',
        '384_234')";
        echo '<hr>'.$sql;
        insert($sql);

With this code I output the image.

header("Content-type: image/jpeg");  
$query = "SELECT Dateigroesse, CONVERT(varchar(max), UnterschriftsBild) as content_data FROM EHS.dbo.T_Signaturen WHERE ID = '10'"; 
$result = query($query);
$content = $result[1]["content_data"];       
$filesize = $result[1]["Dateigroesse"]; 

$content = substr ($content, 2);             // entfernt 0x
$content = pack("H*", $content); 
print $content;  

Everything works fine but only a part of the image is shown. I reduced the image size from 20kb to 2kb and much more is shown so I think ANYWHERE the binary data is cut. The Database Column is a varbinary(max)

Please let us not discuss wether it is rational to store blob in databases :) :)

  • 写回答

2条回答 默认 最新

  • doudong8713 2013-10-15 08:19
    关注

    The solution was to increase the max accepted string length of odbc in php.ini. It was set to 4069 chars

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮