Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Empty record set

    Hi,

    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?

    Thanks

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could use ora_numrows()

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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers

    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.....

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    http://www.php.net/manual/en/function.ocirowcount.php
    and read the usercomment for a possible hack.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Raf

    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.......

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •