oracle function returning sys_refcursor

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, I've had this problem, and managed to solve it now (i don't know
how well yet, but it works) so i thought i'd post the solution because
i couldn't find it anywhere.

The problem I was having was we have lots of functions that return
sys_refcursor's that we use as recordsets through ADO with a windows
application, but then we needed to call these same functions from PHP,
so the solution was to use cursors, like so...


$cnn = OCILogon( 'User', Password', 'TNS' );
$cur = OCINewCursor( $cnn );
$stmt = OCIParse( $cnn, " begin :MyRefCur := MyFunction( 1, 2, 3 );
end; " );

OCIBindByName( $stmt, ":MyRefCur", $cur, -1, OCI_B_CURSOR );
OCIExecute( $stmt );
OCIExecute( $cur );

while ( OCIFetchInto($cur,$row,OCI_ASSOC) )
    foreach ( $row as $name => $value )
        echo "$name = '$value'<br />";

OCIFreeStatement( $stmt );
OCIFreeCursor( $cur );
OCILogoff( $cnn );


Maybe someone else has a better solution?

Re: oracle function returning sys_refcursor

naph wrote:

Quoted text here. Click to load it

I'm constantly amazed how Oracle manages to infest everything it touches.
SQL, C, PHP, it just gets sooooo complicated and unreadable.

There are lots of database abstraction layers for PHP, good ones include dbx
and adodb.


Re: oracle function returning sys_refcursor

On Mon, 21 Nov 2005 06:03:31 -0800, naph wrote:

Quoted text here. Click to load it

Try with .  ADOdb is written to be as similar
to ADO as possible. It supports cursors and it has a nice little tutorial  


Site Timeline