Re: Pl/Sql with php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Sergio Hernandez wrote:


Hi, we are working in php with oracle and we have a stupid problem.

We are trying to obtain the return value of a variable. But after execute the function it give to us an empty value, its return 0 columns and 1 row. We have prove this function in oracle and it give a good result.

The code is :

$sql="declare identificador number; begin identificador:=InsertarObtenerIdArticulo('PruebaFuncion', 1, 500); end;";

$identificador=ora_do($ora_conn, $sql);

I've never used the old Oracle 7 interface for anything serious, and have barely used PHP's driver for it, but try something like this:

<?php

/*
  Sample using "oracle" driver to get the value of a function.

Before running this script create this function using SQL*Plus:

    create or replace function myfunc(myparam IN number) return number as
    begin
          return myparam;
    end;

  Tested with PHP 4.3.3 against Oracle 9.2
*/

$my_db_conn = ora_logon("scott@mydb", "tiger");

$my_cursor = ora_open($my_db_conn);

$sql = "begin :mybindvar := myfunc(500); end;";

ora_parse($my_cursor, $sql, 0);

$r = ora_bind($my_cursor, "mybindvar", ":mybindvar", 4 /* 4? */, 2);

// Set the OUT bind variable to anything (?), otherwise you get:
//    Warning: Can't find variable for parameter
//    Notice: Undefined variable: mybindvar
$mybindvar = 0;

ora_exec($my_cursor);

print 'Return value is: '. $mybindvar;

?>

There's a comment on using OUT bind variable in the oracle driver in
Oracle's PHP forum at:
http://forums.oracle.com/forums/thread.jsp?forum=178&thread=206340

If the PHP and Oracle combination is new to you, the general
recommendation is to use the "oci8" driver where possible instead of
"oracle".  It has several advantages over the old "oracle" driver,
not least being that seems to have better support.  See
http://www.php.net/manual/en/ref.oci8.php


Chris


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux