Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Question Unanswered: Problem with recording a picture in database

    Hello,
    Is there my problem:

    I have a picture recorded in database with this method:
    Code:
    UPDATE myTable SET pictureData = (SELECT * FROM OPENROWSET(BULK 'myFileAdress.jpeg', SINGLE_BLOB)AS x ) WHERE 
    I read this data like this:

    PHP Code:
    $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:
    PHP Code:
    $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
    Php
    IIS
    Attached Thumbnails Attached Thumbnails bad.png   good.png  

  2. #2
    Join Date
    Sep 2011
    Posts
    71
    Hello ,I'm not sure of your way to read the binary picture from the data base ,Because i'm asp.net developer So i'm using file streaming way .To insert and also to extract from data base ,Also there is another way ,May help you which store pic at folder and just store the path to it at DB .
    may I'm helpful

  3. #3
    Join Date
    Sep 2011
    Posts
    71
    Sorry ,About your code to insert i thought it is almost correct ,but may you need to mention the full path for an imageas below code:

    For inserting images in to database i used the following code

    BulkColumn from Openrowset( Bulk 'F:\Images\picture005.jpg', Single_Blob) as tt

  4. #4
    Join Date
    Oct 2011
    Posts
    2

    Wink thanks

    Quote Originally Posted by paultech View Post
    Sorry ,About your code to insert i thought it is almost correct ,but may you need to mention the full path for an imageas below code:
    In fact, that is what is really done, expect I didn't write it for the example given. Also we choose to record data in database for the reason to have all data recoverable or manageable at a time.

    thanks a lot Paultech to thought about my problem.

    Bye

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •