Skip to Content.
Sympa Menu

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

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Martin Rode <martin.rode AT programmfabrik.de>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] php + tds with sql server, retrieving images
  • Date: Thu, 06 Apr 2006 10:41:30 +0200

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





Archive powered by MHonArc 2.6.24.

Top of Page