Link to home
Start Free TrialLog in
Avatar of kuanfai
kuanfai

asked on

Use PHP to read and display Informix blob object

Dear experts:

How can I use PHP to extract a data field in Informix which holds images in .jpeg or .gif format? And also need to show them on web pages.

Thanks

Kuanfai
Avatar of ldbkutty
ldbkutty
Flag of India image

Here's one good example for you:
http://www.prstech.com/src/php/php_info/informix_tech_notes_on_php.html#disdb

Probably, it contains everything what you want.
Avatar of kuanfai
kuanfai

ASKER

But I received NULL with the following statement:

<?php

header("Content-type: image/gif");
/*
Program :    showpiccatalog.php3
Author  :    Mario Estrada
Date    :    05/01/1999
Purpose :    Reads the image from a BLOB column and sends it
             back to the Web browser with the appropriate header.
*/
  /*The following statement ensures that the Web browser will
    recognize the following content as a GIF image */
  $res = ifx_connect("ireach@eipsgp", "informix", "informix");

  $query = "select * from staff_detail where id = 'Q293'";
  //$rid=ifx_prepare($query,$res);
  //ifx_do($rid);
  $rid = ifx_query($query, $res);
  $array=ifx_fetch_row($rid);

  ifx_blobinfile_mode(0);   //0=in memory, 1=in file
  ifx_nullformat(1);
  $tmp=ifx_get_blob($array["photo"]);
  echo $tmp;


  ifx_free_result($rid);
  ifx_close($res);
?>


your Query is : "select * from staff_detail where id = 'Q293'" and you have used ifx_fetch_row() method....

ifx_fetch_row() method returns the associative array....that is, it returns as integer offsets from 0th row or you have to give your name of the row in your SQL statement('photo' in your case).....There is no ifx_fetch_array() exists like in the case of mysql_fetch_array()

So, either you have to do the Query as:

"select photo from staff_detail where id = 'Q293'" and use your same method of  $tmp = ifx_get_blob($array["photo"]);

Or, use:

"select * from staff_detail where id = 'Q293'" and
$tmp = ifx_get_blob($array[2]);  // Here, i assume 2 as 'photo' is your 3rd row of your table (Offset starts from 0th row).

Hope you get me....
Avatar of kuanfai

ASKER

Hi, thanks for your reply. This is what I used:

  $query = "select photo from staff_detail where id = 'Q293'";
  $rid = ifx_query($query, $res);
  $array=ifx_fetch_row($rid);

  ifx_blobinfile_mode(0);   //0=in memory, 1=in file
  ifx_nullformat(1);
  $tmp = ifx_get_blob($array['photo']);

  echo $tmp;

  ifx_free_result($rid);
  ifx_close($res);


but still it returns NULL value. Is the ifx_get_blob( ) right command to retrieve blob object? I noticed that the result of this command is "int".
BLOB's in a table are stored as pointers the actual data. Depending on how the BLOB data was stored when created with ifx_create_blob() , it may either be *stored in memory or as a file pointer*. When extracting the BLOB data from a table using a SELECT statement, the BLOB data ca be retrieved using ifx_get_blob() . However, the BLOB may be stored in either mode. Setting the BLOB mode using this function, explicitly sets the type of BLOB returned.

A setting of 0 in ifx_blobinfile_mode() saves BLOBs in memory, a setting 1 saves BLOBs to file.

>> Is the ifx_get_blob( ) right command to retrieve blob object? I noticed that the result of this command is "int".
It is the CORRECT command to retrieve BLOB. It *retrieves the BLOB contents if true*, 0 if false.

ifx_nullformat() -> Sets the default return value of a NULL-value on a fetch row. Mode "0" returns "", and mode "1" returns "NULL".
So, check whether you have the BLOB object with that ID. The reason you got NULL might be because you dont have BLOB
content....ifx_nullformat(1) returns NULL if the return value on ifx_fetch_row() is NULL.

Try this:
---------

<?php

  $res = ifx_connect("ireach@eipsgp", "informix", "informix");

  $query = "select photo from staff_detail where id = 'Q293'";
  $rid = ifx_query($query, $res);

  ifx_blobinfile_mode(0);   //0=in memory, 1=in file  --> Check whether your BLOB is a file pointer or memory pointer...

  if($array=ifx_fetch_row($rid))
  {
      $tmp=ifx_get_blob($array["photo"]);
      echo $tmp;
  }

  ifx_free_result($rid);
  ifx_close($res);
?>

Do you get any errors/Do you get any blank page/Do you get NULL in the page ---> ?
If NULL page, it means either you dont have the BLOB in that ID or you have file pointer for BLOB(if so, use ifx_blobinfile_mode(1)).

http://www.phpdig.net/ref/rn30re566.html
Avatar of kuanfai

ASKER

Either ifx_blobinfile_mode(0) or ifx_blobinfile_mode(1) returns a blank page to me. But when I refresh a second time, I got this message "NODEFDAC" shown on the page.

Is that mean there is no way to extract the picture from the table any more :(... ?
ASKER CERTIFIED SOLUTION
Avatar of ldbkutty
ldbkutty
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial