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: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] php + tds with sql server, retrieving images
  • Date: Thu, 6 Apr 2006 10:25:35 +0200

>
> hi everybody,
>
> i have
>
> * Debian Linux
> * PHP 4.4.2-1+b1
> * tdsodbc 0.63-2
> * unixodbc 2.2.11-12
>
> My problem is, that via ODBC i can write image binary to the database
> (using the 0x notation), but I can only retrieve 4096 bytes from that
> binary back. What am I doing wrong?
>
> Thanks for your support!
> 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




Archive powered by MHonArc 2.6.24.

Top of Page