Display Image Fields From MSSQL.
Leo Kwan
leo_kwan at hotmail.com
Sun Mar 4 23:46:43 EST 2001
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, at Start, at 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.
More information about the FreeTDS
mailing list