Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2006, 02:02 PM
Registered User
 
Join Date: Oct 2003
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...

Code:
// 
        // 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"> 

        </form> 

        <?php 
        } 
        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); 
          OCIFreeStatement($stmt); 

          // 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'])) { 
            OCICommit($conn); 
            echo "CLOB successfully uploaded\n"; 
          } 
          else { 
            echo "Could not upload CLOB\n"; 
          } 
          $lob->free(); 
          OCIFreeStatement($stmt); 

          // 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; 
          OCIFreeStatement($stmt); 
          OCILogoff($conn); 
        }







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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.