Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of Rows Returned 1

Status
Not open for further replies.

Julzzey

Programmer
Sep 2, 2002
19
US
Hi,

There has to be an easy way to do this, but I don't know what it is. How do I get the number of rows returned when using Php and Oracle? I know how to do the query and execute the statement, but I need to throw an error if there aren't any rows returned.

Thanks!
 
you use the OCIFetchInto function in a loop

$numrows = 0;

while(OCIFetchInto($stmnt, $res,OCI_RETURN_NULLS + OCI_ASSOC))
{
$numrows++;
}


numrows will show the number of rows that has been fetched.

This is how you get $stmnt and $res

$connection =OCILogon("username","password","database string");
$my_query ="select * from table1";
$stmnt = OCIParse ($connection, $my_query);
OCIExecute ($stmnt);


Otherwise if it is an update or insert statement

OCIRowCount($stmnt) will give you the number of rows. This will return 0 for a select query.

If you are not using OCI functions
use ora_numrows($stmnt);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top