Note that there are some explanatory texts on larger screens.

plurals
  1. POrecording a picture in database with sql server and php
    primarykey
    data
    text
    <p>Is there my problem:</p> <p>I have a picture recorded in database with this method:</p> <pre><code>UPDATE myTable SET pictureData = (SELECT * FROM OPENROWSET(BULK 'myFileAdress.jpeg', SINGLE_BLOB)AS x ) WHERE … </code></pre> <p>I read this data like this:</p> <pre><code>$myData = $myConnection-&gt;query('Select pictureData from myTable where …'); $row = $myData-&gt;fetch(PDO::FETCH_ASSOC); echo @pack('H*', $row['pictureData']) </code></pre> <p>In another hand I try directly read this picture file from a Php script as following:</p> <pre><code>$data = fopen ($myPictureAdress, 'rb'); $size = filesize ($picture); echo fread ($data, $size); </code></pre> <p>In fact some octet ('0') are placed with the first method (from the database) and corrupt my picture as seen below.</p> <p>Does anyone knows why this octets are placed there ? Do the insert query is right done?</p> <p>Thanks a lot for your help!</p> <p>System information: </p> <ul> <li>SQL Server 2005</li> <li>Php</li> <li>IIS</li> </ul> <p>good:</p> <pre><code>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 &lt;-- 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 </code></pre> <p>bad:</p> <pre><code>00000100 63 00 63 00 63 00 63 00 63 00 06 00 36 00 36 00 c c c c c 6 6 &lt;-- 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload