Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

How to display/retreive MSSQL image type Field with php


  • Please log in to reply

#1
milosstevic

milosstevic

    New Member

  • Member
  • Pip
  • 2 posts
Hi everyone,

to break it short i have a dektop application that uses a MSSQL server and database for storing its data.So the database is already formed and filled and i cannot alter it. In that database the application stores its product images in field of type image.

I am creating a web site that need to synchronise an online Mysql database reading form the offline MSSQL server. All communication and reading all fields from MSSQL is working OK except that image field. Now i have been working with PHP and Mysql for some time and know how to insert/retreive images to/from a mysql database(using BLOBS). I have tried the same concept first with MSSQL and i just cant get it to work. Does anyone have any experience working with inserting/retreiving images form MSSQL using php.It has been busting my balls for a few days already. Here are the code combinations that i all tried and didnt 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;



?>

If anyone has any advice please POST.
Thanx!
  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP