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):
$link = odbc_connect($odbc_source_name, $user, $pass);
// query (note - one row in this example)
$sql = 'SELECT image_data_column FROM some_table WHERE record_id=1';
$result = odbc_exec ($link, $sql)
trigger_error ('[sql] exec: '.$sql, E_USER_ERROR);
// fetch settings
odbc_binmode ($result, ODBC_BINMODE_PASSTHRU);
odbc_longreadlen ($result, 0);
// get contents
ob_start(); // you would probably need to move this inside if you expect more rows
odbc_result($result, 1); // this actually echos all of the contents of the image_data_column
$contents = ob_get_clean();
(PHP 4, PHP 5)
odbc_longreadlen — Gestione di colonne LONG
(tipi di campi ODBC ed SQL coinvolti: LONG, LONGVARBINARY) Tramite l'argomento lunghezza si controlla il numero di byte da ritornare a PHP. Se il campo viene posto a 0, i dati della colonna saranno passati direttamente al client.
Nota: Per la gestione delle colonne di tipo LONGVARBINARY si utilizza anche odbc_binmode().
In my current situation, odbc_binmode(), odbc_longreadlen() and the lrl-setting in the php.ini do not help. But when I remove the DISTINCT from my SELECT-query, it works. I guess in my case DISTINCT truncates the data somehow. Hope that helps someone.
If you are experiencing troubles with truncated and/or strangely encoded data when using PHP with MS SQL via ODBC try setting odbc.defaultlrl ( in php.ini or via ini_set() ) to a largish number, say 65536, as stated in the other notes here.
The trick is to know how long your data is going to be, so you may want to provide some overhead. Unfortunately you have to know how long your piece of string is before you cut it.
Doing this will allow your app to read up to this amount in one go. I'm sure there is a reason for this behaviour but I hadn't experienced anything like it in 5 years of MySQL and Postgres development.
If you still experience problems AND are using unicode data in the long column of your table, make sure it is set to type "ntext", if it is "text". MSDN has some info on data types for Unicode data.
This caused about 3 days of headaches for me, "binary" data crashing browsers and cyclical result sets (i.e repeating data after odbc.defaultlrl bytes).
This fix was only found by poking things with sticks.
I was reading from a MEMO field (long varchar) in MSAccess, but the data was consistently truncated at 255 characters. I tried all the combinations of odbc_longreadlen() and odbc_binmode() (and odbc.defaultlrl) that I could think of but none of them resolved the problem.
The only fix that worked was to modify my query from "SELECT Field1, Field2 FROM TableName" to "SELECT * FROM TableName".
I suspect that you could cast the field to force the appropriate data type, but when it finally worked after three days of struggle I didn't even try.
An alternative is to adjust your php.ini file and set:
Or something else sufficiently large.
lrl = long read length
I was wondering about truncated data when reading from a TEXT (LONG VARCHAR) column.
With this I was able to increase the buffer size...
I had a heck of a time figuring out what to do with this function. Here's a little piece of code from Jason Lee which I found that might help someone else...
$cur = odbc_exec($cnx, $query);
/* error handler */
odbc_longreadlen($cur, 16384); /* Allow 16kb thru */
$bigger_than_4096_var = odbc_result($cur, 1);
/* etc... */
Hope this helps someone, John