views:

17

answers:

0

Hi Everyone,

I am creating a web site that needs to synchronise an online MySQL database reading from the offline MSSQL server. All communication and reading all fields from MSSQL is working OK except that image field. I have been working with PHP and Mysql for some time and know how to insert/retrieve images to/from a MySQL database(using BLOBS). I have tried the same concept first with MSSQL and I just can't get it to work. Does anyone have any experience working with inserting/retrieving images from MSSQL using php? It has been busting my balls for a few days already.. Here are the code combinations that I have tried and didn't work..

<
?php

$conn = mssql_connect("COMP1");
mssql_select_db("datalab",$conn);


// storing a file
$datastring = file_get_contents("banner.jpg");
$data = unpack("H*hex", $datastring);
mssql_query("insert into milos (id,naziv, slika)
values ('2','img2.jpg', 0x".$data['hex'].")");

// retrieving


$result = mssql_query("select slika from milos where naziv = 'img2.jpg'");
$row = mssql_fetch_array($result);
header("Content-type: image/jpeg;");

$data = $row['slika'];



echo $data;


//echo $slika;


?>

<
?php


$conn = mssql_connect("COMP1");
mssql_select_db("datalab",$conn);


$result = mssql_query("select slika from milos where naziv = 'img.jpg'");
$row = mssql_fetch_array($result);
header("Content-type: image/jpeg;");

$data = $row['slika'];

$datas = substr($data,78);


echo $datas;




?>

<
?php

$conn = mssql_connect("COMP1");
mssql_select_db("datalab",$conn);



$result = mssql_query("select slika from milos where naziv = 'img.jpg'");
$row = mssql_fetch_array($result);
header("Content-type: image/bmp;");

$data = $row['slika'];
$data_pos = strpos($data,"JFIF");
$datas = substr($data,$data_pos - 6);

echo $datas;



?>

Can any one help me?

Thanks in advance.. Nimmy....