Skip to Content.
Sympa Menu

freetds - Re: Display Image Fields From MSSQL.

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Leo Kwan" <leo_kwan AT hotmail.com>
  • To: freetds AT franklin.oit.unc.edu
  • Subject: Re: Display Image Fields From MSSQL.
  • Date: Sun, 4 Mar 2001 23:46:43 -0500


I hope this can help you.

CREATE PROCEDURE sp_Image2vchar
@ProductCode int
AS

DECLARE @Count int
Declare @Start int
Declare @NextLen int

select @Count = datalength(Cover) from product where
productcode=@ProductCode

select @NextLen = 4096
select @start = 1
create table #T (Cover text, NextLen int)
while (@Count > 0)
begin
if (select @count) < @nextlen
begin
select @NextLen = @count
end

insert into #T select
convert(text(4096),convert(varchar(4096),substring(Cover,@Start,@NextLen)))
as Cover, @Nextlen
as OutLength from Products where productcode = @ProducTCode

select @count = @count - @NextLen
select @Start =@start + @NextLen
end
select * from #t
=======================================
We cannot directly convert image data type to text type, so we have to
change it to varchar first and then convert it to text.

In php.
================
$ConnID = sybase_connect ("mssql","username","password");
$result = sybase_query("sp_image2vchar 1437");

$info = sybase_fetch_field($result);
echo "<BR>Type = ".$info->type;
echo "<BR>Max_length = ".$info->max_length;
echo "<BR>Name = ".$info->name;

$rows = sybase_num_rows($result);
echo "<BR>Total rows = ".$rows;
$par = sybase_fetch_object($result);
echo "<BR> Par Type = ".$par;

$fp = fopen ("/var/www/html/temp/hoho.gif","wb");
for ($i = 0 ; $i < $rows; $i++)
{
sybase_data_seek($result,$i);
$par = sybase_fetch_object($result);
echo "<BR>$i = ".$par->NextLen;
echo fwrite ($fp,$par->Cover,$par->NextLen);
}
fclose ($fp);

===================
The file in /var/www/html/temp/hoho.gif is what you get from MSSQL.





Archive powered by MHonArc 2.6.24.

Top of Page