0

I need to retrieve some images saved in a blob field of a db400 table. I'm trying with PHP ODBC library, this is the example code:

    //connect to database 
    if(!$conn = odbc_connect($DNS, $user, $password)){
        exit("Error");
    }

    $sql = "SELECT TSMIME, TSIMG 
            FROM SVMAGDAT.DFW3S00F 
            WHERE TSIDMO=17 and TSPRMO=0";
    $result = odbc_exec($conn, $sql);

    $type=$lob="";
    if ($result) {                            
        odbc_longreadlen($result, 5242880);//5MB      
        odbc_binmode($result,ODBC_BINMODE_CONVERT);

        $type = odbc_result($result, "TSMIME");
        $lob = odbc_result($result, "TSIMG");
    }

    echo "<img src=\"data:$type;base64,$lob\" >";  

The images are saved with base64 encode and with his query i get only one row. I've tryed changing odbc_longreadlen and odbc_binmode with no results.

With this configuration $lob variable is blank while $type is correctly set.

If i set odbc_binmode to ODBC_BINMODE_PASSTHRU i can't see any result because the browser crash everytime.

Any suggestion?

Thanks

fonta7
  • 64
  • 1
  • 4
  • Usually you have something like a for / foreach loop to itterate via all result rows. – André Schild Jun 29 '15 at 13:10
  • Yes, but in this simplified example i have only 1 row as result so i don't need to loop resultset. – fonta7 Jun 29 '15 at 13:46
  • Have you tried with another browser? Looks like your image encoding is not what you tell the browser it should be bet. Alternatively, use something like wget to retrieve the full content of the html page, you could then look at what is returned to the webbrowser – André Schild Jun 29 '15 at 13:51

0 Answers0