Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 30th, 2006, 02:02 PM
Registered User
Join Date: Oct 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving clob oracle with php

After a search I found a few results, but none were in PHP environment.

what I'm trying to do is have a user upload a pdf file into an oracle database. (as a clob data type) I can upload no problem, but it comes time to retrive the info into a pdf file I get 2 outcomes depending on how I tamper with the php code.
1) the pdf file opens, but it's empty.
2) I get a format error and the pdf file does not open

When I check if the info is actually in oracle, everything seems to be ok at the database level. I figure I'm doing something wrong in php when I insert the data or when i'm trying to retrieve the data. I am using oracle 10g.

Any help would be greatly appreciated...

In case I lost some of you with my explanation, I am inserting a pdf file into oracle and want to retrive it in the pdf reader. Thats all...

here is the code I'm using...

        // Sample form to upload and insert data into an ORACLE CLOB column 
        // using PHP's Oracle 8 API. 
        // Based on http://www.php.net/manual/en/functio...descriptor.php 
        // modified to work on CLOBs and use register_globals = Off. 
        // Before running this script, execute these statements in SQL*Plus: 
        //   drop table myclobtab; 
        //   create table myclobtab (c1 number, c2 clob); 
        // Tested with PHP 4.3.3 against Oracle 9.2 

        if (!isset($_FILES['lob_upload'])) { 

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> 
        Upload file: <input type="file" name="lob_upload"> 
        <input type="submit" value="Upload"> 


        else { 
          $myid = 1; // should really be a unique id e.g. a sequence number 

          $conn = OCILogon('myusername', 'mypassword', 'mydatabase'); 

          // Delete any existing CLOB so the query at the bottom 
          // displays the new data 

          $query = 'DELETE FROM MYCLOBTAB'; 
          $stmt = OCIParse ($conn, $query); 
          OCIExecute($stmt, OCI_COMMIT_ON_SUCCESS); 

          // Insert the CLOB from PHP's temporary upload area 

          $lob = OCINewDescriptor($conn, OCI_D_LOB); 
          $stmt = OCIParse($conn, 'INSERT INTO MYCLOBTAB (C1, C2) VALUES('.$myid . ', EMPTY_CLOB()) RETURNING C2 INTO :C2'); 
          OCIBindByName($stmt, ':C2', &$lob, -1, OCI_B_CLOB); 
          OCIExecute($stmt, OCI_DEFAULT); 

          // The function $lob->savefile(...) reads from the uploaded file. 
          // If the data was already in a PHP variable $myv, the 
          // $lob->save($myv) function could be used instead. 
            if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) { 
            echo "CLOB successfully uploaded\n"; 
          else { 
            echo "Could not upload CLOB\n"; 

          // Now query the uploaded CLOB and display it 
          $query = 'SELECT C2 FROM MYCLOBTAB WHERE C1 = '.$myid; 
          $stmt = OCIParse ($conn, $query); 
          OCIExecute($stmt, OCI_DEFAULT); 
          OCIFetchInto($stmt, $arr, OCI_ASSOC); 
          $result = $arr['C2']->load(); 
          header("Pragma: no-cache"); 
          header('Content-type: application/pdf'); 
          header('Content-Disposition: attachment; filename="downloaded.pdf"'); 
          echo $result; 

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Asp/Oracle-Clob Thiago Classic ASP Databases 2 January 26th, 2009 09:03 AM
Oracle stored procedure with clob return Alok Singh Oracle ASP 1 January 31st, 2008 07:53 AM
Help for retrieving info from javascript to PHP anandramv Pro PHP 6 December 22nd, 2006 06:11 AM
Sending & Retrieving Picture From Oracle To VB tutul128 Pro VB Databases 1 October 31st, 2004 06:41 AM
comparing CLOB fields pankaj_daga Access 0 August 5th, 2004 04:38 AM

All times are GMT -4. The time now is 10:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.