[freetds] php + tds with sql server, retrieving images

Martin Rode martin.rode at programmfabrik.de
Thu Apr 6 04:41:30 EDT 2006


Hi Freddy,

I tried the same with

odbc_exec($link2, "SET TEXTSIZE 100000;"); // also 0 dont work
....
odbc_longreadlen($result, 20000);

and it still does not work.

What am I missing here?

Best,
Martin





> This is che default setting, use SET TEXTSIZE xx where xx is the limit
> you want (0 for no limit that is 2GB)
>
>   
>> PHP script comes here:
>> --------------------------------------------------------------
>> ----------------------------
>>
>> $dsn ="DRIVER={FreeTDS};SERVER=thepope;DATABASE=test";
>> $link2 = odbc_connect($dsn , 'sa', 'test' ) or die(odbc_errormsg() );
>>
>> $datastring = file_get_contents("/home/martin/jpegs/goil.jpg");
>>
>> odbc_autocommit($link2, true);
>>
>> odbc_exec($link2, "IF EXISTS(SELECT TABLE_NAME FROM 
>> INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'images') DROP TABLE 
>> [images];");
>>
>>
>> odbc_exec($link2, "
>>  CREATE TABLE images (
>>     name varchar(50),
>>     data image
>> );");
>>
>> $data = 
>> odbc_escape_string(file_get_contents("/home/martin/jpegs/goil.jpg"));
>>
>>     
>
> I would try prepared statement, it do not need to quote image.
>
>   
>> $sql = "insert into images (name, data) values ('img.jpg',$data);";
>> odbc_exec($link2,$sql);
>>
>> // retrieving: this only gives me 4096 bytes
>> $result = odbc_exec($link2, "select data from images;");
>> header("Content-Type: image/jpg");
>> odbc_longreadlen($result, 8192);
>> $row = odbc_fetch_array($result);
>> echo $row['data'];
>>
>>
>> function odbc_escape_string($datastring) {
>>     $data = unpack("H*hex", $datastring);    
>>     return '0x'.substr($data[hex],0,strlen($data[hex])-1);
>> }
>>     
>
> freddy77
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>   




More information about the FreeTDS mailing list