0

I have been fighting with this for days now. Can't seem to get to the bottom of it. I have a Sybase table that has a long binary field which contains a jpg. I am pulling the pictures from the table using this query. PHP.ini file has memory_limit = 4096M

SELECT TOP 1 base64_encode(ImageData) as img, IL.Description As alt
     FROM ProductImage PI
    JOIN ImageLibrary IL
    ON PI.ImageId = IL.ImageId
    WHERE PI.ProductCode = '3894'
ORDER BY PI.ImageOrder 

If I select the length of the imagedata as below:

 SELECT length(ImageData) as img, IL.Description As alt
     FROM ProductImage PI
    JOIN ImageLibrary IL
    ON PI.ImageId = IL.ImageId
    WHERE PI.ProductCode = '3894'
ORDER BY PI.ImageOrder

This returns 38924

However when I run the query in php and loop over the result I only get 4096 as the length.

<?php

    /// GET THE IMAGE FROM IMAGE LIBRARY
    
    $conn = odbc_connect($connect_string,'','');
    $Image='';
    $Alt ='';
    $query='';  
    $query = "SELECT TOP 1 base64_encode(ImageData) as img, IL.Description As alt";
    $query .= " FROM ProductImage PI";
    $query .= " JOIN ImageLibrary IL ";
    $query .= " ON PI.ImageId = IL.ImageId";
    $query .= " WHERE PI.ProductCode = '3894'";
    $query .= " ORDER BY PI.ImageOrder";    
    //var_dump ($query);
    $res =      odbc_exec($conn,$query)or die("Whoops! I could not run this query " . $query);
    $num_rows = odbc_num_rows($res) & 0xffffffff;     
    $rows =     array();
   
    while (odbc_fetch_row($res)) {    

      
   $len = strlen(odbc_result($res,"img"));
   

   If ($len > 0){     
      $image = odbc_result($res,"img");
      $alt   = odbc_result($res,'alt');
    } else {    
      $image='No Image binary goes here'
      $alt = 'No Image saved sorry';     
     } 
  } 
 
?>

  • https://www.php.net/manual/en/function.odbc-execute.php#16694: _"odbc has a maximum buffer size, that means it only stores and retrieves a limited size of data to/from database each time. The maximum buffer size is 4096 and set in php.ini (odbc.defaultlrl). You can set it to higher value for larger data access."_ – CBroe Mar 07 '23 at 10:03
  • Sorry I'm only getting back to you now. Many thanks that appears to have done the trick! – AmbientGuitar May 09 '23 at 11:57

0 Answers0