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