I've tried to use a suggestion in the first comment but that didn't actually worked as I would expect... I wanted to get all data no matter how big it is, but strange things happened and I finally found this solution (works fine at least for MS SQL 2000 for at least few MB of binary data):
<?php
$link = odbc_connect($odbc_source_name, $user, $pass);
$sql = 'SELECT image_data_column FROM some_table WHERE record_id=1';
$result = odbc_exec ($link, $sql)
if (!$result)
{
trigger_error ('[sql] exec: '.$sql, E_USER_ERROR);
}
odbc_binmode ($result, ODBC_BINMODE_PASSTHRU);
odbc_longreadlen ($result, 0);
ob_start(); while (odbc_fetch_row($result))
{
odbc_result($result, 1); }
odbc_free_result($result);
$contents = ob_get_clean();
?>