Retrieve BLOB field from db2 AS/400 using PHP ODBC library

631 Views Asked by At

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

0

There are 0 best solutions below