Hi
I need to call a oracle function, but i need to bind one variable to get a value.

if a use php code and oci, i call the function:
$sql1="begin :RESULT :=WEBFUNCTION( ".
" price => 'S',".
" unit => 10 );end;";
$stmt=ociparse($conn,$sql1);
ocibindbyname($stmt,":RESULT",$result,50);
ociexecute($stmt);

At Drupal, with oracle:
db_set_active('oracle'); // set external database oracle
$stmt = db_query($sql1)->execute(); // execute function
db_set_active(); // set default internal database

I get error: "OCIStmtExecute: ORA-01008" because I don't bind the varible ":RESULT"

How i can bind that variable?
Can you help me?

Comments

aaaristo’s picture

you can do somenthing like this... there are many examples of PDO::PARAM_INPUT_OUTPUT in the database.inc i think...

       $conn= Database::getConnection('oracle');

       $stmt= $conn->oraclePrepare("begin ? := WEBFUNCTION; end;");
       $stmt->bindParam(1, $retval, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 32);

       $stmt->execute();

       echo $retval;
Anonymous’s picture

Thanks aaaristo!

But I have one problem, i change my code, and that error appears:
"Fatal error: Call to undefined method DatabaseStatementPrefetch::bindParam() in C:\wamp\www\project\includes\database\oracle\database.inc on line 632"

What am I doing wrong?

aaaristo’s picture

i changed the example above to use the DatabaseConnection_oracle::oraclePrepare method, because you need to go directly with PDO to do this.

You should add this method in database.inc:


  public function oraclePrepare($query)
  {
      return parent::prepare($query);
  }


Anonymous’s picture

Fantastic! Thanks!
I will change my code for test that solution, it will work!
One question, I'm doing a module, I can put

<?php
  public function oraclePrepare($query)
  {
      return parent::prepare($query);
  }
?>

into my module?, for not change code of drupal core or contrib modules?
If it's possible, I need to change anything in that function?

aaaristo’s picture

you should add it to the database.inc of the oracle module... i'll add it to the next release

aaaristo’s picture

Status: Active » Fixed

in 1.10

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.