SQL Server Performance

Problem with recording a picture in database

Discussion in 'SQL Server 2005 General DBA Questions' started by bat, Oct 28, 2011.

  1. bat New Member

    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 in the two screenshots joined.

    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




    bad.png good.png
  2. satya Moderator

    Welcome to the forums.
    How frequently are you updating the picture here?
    I see that you are trying to replace the value from that field which is picture, I would also recommend to visit PHP related forums to see if any counters can help.
  3. bat New Member

    I update the picture only once, to put data in database, then I just access to the data.

    Thanks for your answer

Share This Page