Advertisement

09.23.2008 at 11:08PM PDT, ID: 23757602 | Points: 50
[x]
Attachment Details

Php with Oracle BFILE

Asked by raju1 in Oracle 10.x, PHP and Databases

Tags: , ,

Dear Experts,
Pls help me to recover the following error:

Error Description:
-----------------

Warning: oci_execute() [function.oci-execute]: ORA-06550: line 1, column 8: PLS-00103: Encountered the symbol

"" when expecting one of the following: begin function package pragma procedure subtype type use <an

identifier> <a double-quoted delimited-identifier> form current cursor in

E:\WebServer\Apache2\htdocs\test_bfile_select.php on line 48
1: /

Database Scripts
----------------
CREATE TABLE MYLOBS
(
  ID       NUMBER,
  MYLOB    CLOB,
  MYBFILE  BFILE
)

CREATE OR REPLACE DIRECTORY
IMAGES_DIR AS
'E:\WebServer\Apache2\htdocs\test_images';


GRANT READ ON DIRECTORY  IMAGES_DIR TO SCOTT;




bfile_insert.php
----------------
<?php
$conn = oci_connect('scott', 'tiger', '//localhost/orcl');

// Build an INSERT for the BFILE names
$sql = "INSERT INTO
        mylobs
          (
            id,
            mybfile
          )
       VALUES
          (
            mylobs_id_seq.NEXTVAL,
            /*
            Pass the file name using the Oracle directory reference
            I created called IMAGES_DIR
            */
            BFILENAME('IMAGES_DIR',:filename)
          )";

$stmt = oci_parse($conn, $sql);

// Open the directory
$dir = 'E:\\Web\\WebServer\\Apache2\\htdocs\\login5\\test_images';
$dh = opendir($dir)
    or die("Unable to open $dir");

// Loop through the contents of the directory
while (false !== ( $entry = readdir($dh) ) ) {
   
    // Match only files with the extension .jpg, .gif or .png
    if ( is_file($dir.'/'.$entry) && preg_match('/\.(jpg|gif|png)$/',$entry) ) {
       
        // Bind the filename of the statement
        oci_bind_by_name($stmt, ":filename", $entry);
       
        // Execute the statement
        if ( oci_execute($stmt) ) {
            print "$entry added\n";
        }        
    }
   
}
oci_close($conn);
?>




bfile_select.php
----------------
<?php
$conn = oci_connect('scott', 'tiger', '//localhost/orcl');

$sql = "SELECT
          id
        FROM
          mylobs
        WHERE
          -- Select only BFILES which are not null
          mybfile IS NOT NULL";

$stmt1 = oci_parse($conn, $sql);

oci_execute($stmt1)
    or die ("Unable to execute query\n");

$sql = "DECLARE
          locator BFILE;
          diralias VARCHAR2(30);
          filename VARCHAR2(30);
           
        BEGIN
         
          SELECT
            mybfile INTO locator
          FROM
            mylobs
          WHERE
            id = :id;
         
          -- Get the filename from the BFILE
          DBMS_LOB.FILEGETNAME(locator, diralias, filename);
         
          -- Assign OUT params to bind parameters
          :diralias:=diralias;
          :filename:=filename;
         
       END;";

$stmt2 = oci_parse($conn, $sql);

while ( $row = oci_fetch_assoc ($stmt1) ) {
   
    oci_bind_by_name($stmt2, ":id", $row['ID']);
    oci_bind_by_name ($stmt2, ":diralias", $diralias,30);
    oci_bind_by_name ($stmt2, ":filename", $filename,30);
   
    oci_execute($stmt2);
    print "{$row['ID']}: $diralias/$filename\n";
   
}
oci_close($conn);
?>

-------------------
This code is from http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/fuecks_lobs.html

Pls help,
Regards,
RajuStart Free Trial
[+][-]09.24.2008 at 12:39PM PDT, ID: 22563271

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.24.2008 at 09:31PM PDT, ID: 22566265

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.24.2008 at 09:39PM PDT, ID: 22566293

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.25.2008 at 01:36AM PDT, ID: 22567184

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.26.2008 at 10:22AM PDT, ID: 22581698

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.26.2008 at 01:29PM PDT, ID: 22583463

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.07.2008 at 07:37AM PDT, ID: 22659812

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.07.2008 at 07:42AM PDT, ID: 22659865

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 06:18AM PDT, ID: 22668639

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628