View Full Version : Empty record set

12-11-2003, 02:30 PM

I know how to test for an empty record set in mysql but i'm stuck when trying to do the same in oracle.

My results come out of a function as a ref cursor and I loop through in a while loop. How can i check if the recordset is empty in PHP?


12-11-2003, 03:40 PM
you could use ora_numrows()

http://be.php.net/manual/en/function.ora-numrows.php and test if its ' >= 1'

12-12-2003, 10:30 AM

In my while loop I have tried:

echo ora_numrows($data);

to return the number of rows but i don't get anything displayed on the screen....

I'm using OCI functions throughout my app - not used any ora functions.....

12-12-2003, 10:59 AM
you need to put the ora_numrows before the while loop.

there doesn't seam to be an oci function for this. Very strang, but check out
and read the usercomment for a possible hack.

12-12-2003, 12:15 PM

ora_numrows is an invalid function for me so I tried:

while ($numrows = (OCIFetchInto($curs,&$data))) {
echo $numrows;

but again nothing cam out......

any ideas on what to try?

Maybe I could try it in the select.......

12-12-2003, 01:26 PM
You probably can't do it in the select. (It's not possible for the sql-versions i know. Don't know Oracle-sql functions)

But you can run a second select, like

select count(*) as num from table ...

then you'll get a recordset with 1 variable (num) and 1 row.

This will probably be a realy fast executed querys, if you have an index on that table (since oracle optimizes this function then)

If you proces the records, then you can include an incrementing variable inside the loop.

A third option is storing the recordst in an array and then request a count for that array, with count($array)