How to find recordset count from .mdb database

How can I tell if any recordset or how many recorset are returned from the statement below?

$rs1 = odbc_exec($conn,$sql);
rrhandle8Asked:
Who is Participating?
 
Alex-w474Connect With a Mentor Commented:
There may be now way to detect how many records are returned except iterating through the recordset till the end or executing SQL statement with COUNT(*) function as follows:

$rs1 = odbc_exec($conn, 'select count(*) from (' . $sql . ') cnt');
if (odbc_fetch_row($rs1)) {
  $cnt = odbc_result($rs1, 1);
}

Open in new window

0
 
Alex-w474Commented:
0
 
rrhandle8Author Commented:
$numrows = odbc_num_rows($rs1);
Always returns -1
0
 
Loganathan NatarajanLAMP DeveloperCommented:
odbc_num_rows(), This function will return -1 on error, ....there is an error on your $rs1 .. record set .. just check it., then pass the valid rs source.,

0
 
Alex-w474Commented:
So if you need to check whether records returned or not, you can use the following code:

$rs1 = odbc_exec($conn,$sql);
$isEmpty = (false == odbc_fetch_row($rs1));

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.