Oracle and PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jfranz
Forum Newbie
Posts: 2
Joined: Fri Jan 09, 2004 1:02 pm

Oracle and PHP

Post by jfranz »

I am trying to connect to Oracle 9i db. I am trying to query for a jpeg. I keep on recieving a windows download popup after executing the webpage. I have enclosed the code. The sql is correct. Dont know what else is wrong. PHP and GD is setup correctly. I can view jpegs through php. Thanks.

Code: Select all

<?php
  $username = "xxxxxxxx"; 
$passwd = "xxxxxxxxx"; 
$db="xxxxxxxxxx"; 

$conn = OCILogon($username,$passwd,$db); 
if (!$conn) &#123; 
   echo "Connection failed"; 
   echo "Error Message: &#1111;" . OCIError($conn) . "]"; 
   exit; 
&#125; 
else 
&#123; 
   echo "Successfully Connected to Database!\n\n"; 
&#125;   
;
   $conn = OCILogon($user, $password,$db );
   $query = "select dbd_image from database where patronid ='11111111'"; 
   $stmt = OCIParse($conn, $query);
   $err = OCIExecute($stmt);

   OCIFetchInto($stmt);

	header('Content-Type: image/jpg');
	print $stmt;

   ocilogoff($conn);

 ?>
jfranz
Forum Newbie
Posts: 2
Joined: Fri Jan 09, 2004 1:02 pm

Answer my own question!

Post by jfranz »

The query is written correctly. I was recieving the picture in its binary form and not a jpeg. The code below needed to be added to display the picture as a jpeg. The code needed to be place over the original "header" info.

Code: Select all

imagecreatefromstring ($pic);               //creates and puts pic in memory
header('Content-Type: image/jpeg');    //diplay format in browser
imagejpeg($pic);                               //changes pic to jpeg
imagedestroy($pic);                          //Frees up image from memory   
echo "$pic";                                     //displays image
Post Reply