Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

How to read image field from MSSQL 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