8 Replies - 3926 Views - Last Post: 07 May 2012 - 01:39 AM Rate Topic: -----

#1 ccm0707  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Read blob data from mysql database in PHP

Posted 02 May 2012 - 07:59 PM

<?php
	$user = "root";
	$pass = "";
	$db = "sign";
	
	$link = mysql_connect("localhost",$user,$pass)
		or die("connection failed");
	
	mysql_select_db($db,$link)
		or die(mysql_error());
		
	$query = "SELECT signature FROM signdb";

	$result = mysql_query($query);
	
	while($row = mysql_fetch_array($result)){
		header('content-type = image/jpeg');
		echo $row['signature'];
		}
?>


when i want get the blob data from mysql it show me numeric code (like this [{\"lx\":91,\"ly\"..) but not a image so it is i left any code or something wrong inside here? will appreciate if can solve this out.

Is This A Good Question/Topic? 0
  • +

Replies To: Read blob data from mysql database in PHP

#2 sBorg  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 28
  • Joined: 24-March 12

Re: Read blob data from mysql database in PHP

Posted 02 May 2012 - 11:34 PM

header('content-type = image/jpeg');


I think that should be
 header("Content-type: image/jpeg"); 

This post has been edited by sBorg: 02 May 2012 - 11:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,581
  • Joined: 08-June 10

Re: Read blob data from mysql database in PHP

Posted 03 May 2012 - 02:25 AM

that and you can only show exactly one image at a time (i.e. no loop). bear in mind that you request a single image per image URL (not all images with one URL).
Was This Post Helpful? 0
  • +
  • -

#4 ccm0707  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: Read blob data from mysql database in PHP

Posted 04 May 2012 - 12:32 AM

View PostDormilich, on 03 May 2012 - 05:25 PM, said:

that and you can only show exactly one image at a time (i.e. no loop). bear in mind that you request a single image per image URL (not all images with one URL).

thanks for reply, anyway how if i want to do loop display? it is possible?
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,581
  • Joined: 08-June 10

Re: Read blob data from mysql database in PHP

Posted 04 May 2012 - 01:18 AM

itís not possible. you can only have one image per URL.
Was This Post Helpful? 0
  • +
  • -

#6 ccm0707  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: Read blob data from mysql database in PHP

Posted 07 May 2012 - 12:38 AM

View PostDormilich, on 04 May 2012 - 04:18 PM, said:

itís not possible. you can only have one image per URL.

thanks again, actually i'm used to display the signature that i capture and store in mysql, so i can't use bolb to regenerate the signature out with loop? so which file type should i use?
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,581
  • Joined: 08-June 10

Re: Read blob data from mysql database in PHP

Posted 07 May 2012 - 01:02 AM

it doesnít matter if you save the image itself in the DB or only its path. if you request one image (via URL) you must serve exactly one image. period.

bear in mind that images in HTML are displayed by means of the <img> element, which requires exactly one URL for the image (as a kind of parameter). if you do not intend to output the image itself (e.g. if youíre outputting HTML), then the one-to-one restriction doesnít apply.
Was This Post Helpful? 0
  • +
  • -

#8 ccm0707  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 25-April 12

Re: Read blob data from mysql database in PHP

Posted 07 May 2012 - 01:15 AM

can i have example of your explanation, quite blur and im new in this img output things, sorry for that
Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,581
  • Joined: 08-June 10

Re: Read blob data from mysql database in PHP

Posted 07 May 2012 - 01:39 AM

if you have the image itself in the DB:
<?php
// call as http://example.org/image.php?id=123

// "SELECT img_data FROM mytable WHERE id = ?";
$data = getImageById($_GET["id"]); // query DB for image
header("Content-Type: image/jpeg");
echo $data;


if you have only the path and query for the image
<?php
// call as http://example.org/image.php?id=123

// "SELECT img_path FROM mytable WHERE id = ?";
$path = getImagePathById($_GET["id"]); // query DB for image
header("Content-Type: image/jpeg");
echo file_get_contents($data);


if you have the path and display a couple of images
<?php
// note the difference in the call!
// call as http://example.org/my_images.php

$img = '<img src="%s">';

// note the missing condition!
// "SELECT img_path FROM mytable"
$data = getImages();

foreach ($data as $path)
{
    printf($img, $path);
}


general note, these demos are for showing the principle, they do not work as is.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1