使用sql server和php在数据库中记录图片
我的问题是这样吗:
我用这种方法在数据库中记录了一张图片:
UPDATE myTable
SET pictureData = (SELECT * FROM OPENROWSET(BULK 'myFileAdress.jpeg', SINGLE_BLOB)AS x )
WHERE …
我像这样读取这个数据:
$myData = $myConnection->query('Select pictureData from myTable where …');
$row = $myData->fetch(PDO::FETCH_ASSOC);
echo @pack('H*', $row['pictureData'])
另一方面,我尝试直接从 Php 脚本读取这个图片文件,如下所示:
$data = fopen ($myPictureAdress, 'rb');
$size = filesize ($picture);
echo fread ($data, $size);
事实上,一些八位字节('0')是使用第一种方法(来自数据库)放置并损坏了我的图片,如下所示。
有谁知道为什么这个八位字节放在那里?插入查询是否正确完成?
非常感谢您的帮助!
系统信息:
- SQL Server 2005
- Php
- IIS
好:
000000D0 38 00 42 00 63 00 63 00 63 00 63 00 63 00 63 00 8 B c c c c c c <-- no error
000000E0 63 00 63 00 63 00 63 00 63 00 63 00 63 00 63 00 c c c c c c c c
000000F0 63 00 63 00 63 00 63 00 63 00 63 00 63 00 63 00 c c c c c c c c
00000100 63 00 63 00 63 00 63 00 63 00 63 00 63 00 63 00 c c c c c c c c
坏:
00000100 63 00 63 00 63 00 63 00 63 00 06 00 36 00 36 00 c c c c c 6 6 <-- error
00000110 36 00 36 00 36 00 36 00 36 00 36 00 36 00 36 00 6 6 6 6 6 6 6 6
00000120 36 00 36 00 36 00 36 00 36 00 36 00 36 00 36 00 6 6 6 6 6 6 6 6
Is there my problem:
I have a picture recorded in database with this method:
UPDATE myTable
SET pictureData = (SELECT * FROM OPENROWSET(BULK 'myFileAdress.jpeg', SINGLE_BLOB)AS x )
WHERE …
I read this data like this:
$myData = $myConnection->query('Select pictureData from myTable where …');
$row = $myData->fetch(PDO::FETCH_ASSOC);
echo @pack('H*', $row['pictureData'])
In another hand I try directly read this picture file from a Php script as following:
$data = fopen ($myPictureAdress, 'rb');
$size = filesize ($picture);
echo fread ($data, $size);
In fact some octet ('0') are placed with the first method (from the database) and corrupt my picture as seen below.
Does anyone knows why this octets are placed there ? Do the insert query is right done?
Thanks a lot for your help!
System information:
- SQL Server 2005
- Php
- IIS
good:
000000D0 38 00 42 00 63 00 63 00 63 00 63 00 63 00 63 00 8 B c c c c c c <-- no error
000000E0 63 00 63 00 63 00 63 00 63 00 63 00 63 00 63 00 c c c c c c c c
000000F0 63 00 63 00 63 00 63 00 63 00 63 00 63 00 63 00 c c c c c c c c
00000100 63 00 63 00 63 00 63 00 63 00 63 00 63 00 63 00 c c c c c c c c
bad:
00000100 63 00 63 00 63 00 63 00 63 00 06 00 36 00 36 00 c c c c c 6 6 <-- error
00000110 36 00 36 00 36 00 36 00 36 00 36 00 36 00 36 00 6 6 6 6 6 6 6 6
00000120 36 00 36 00 36 00 36 00 36 00 36 00 36 00 36 00 6 6 6 6 6 6 6 6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将二进制数据的十六进制值存储在数据库中。一旦我读了它,我就读了十六进制并将其转换为二进制。
I Store Hex value of the binary data in the Database . once i read it i read the hex and convert it to binary.