Solved

How to find recordset count from .mdb database

Posted on 2008-06-18
5
555 Views
Last Modified: 2008-06-20
How can I tell if any recordset or how many recorset are returned from the statement below?

$rs1 = odbc_exec($conn,$sql);
0
Comment
Question by:rrhandle8
  • 3
5 Comments
 
LVL 5

Expert Comment

by:Alex-w474
ID: 21818518
0
 

Author Comment

by:rrhandle8
ID: 21818635
$numrows = odbc_num_rows($rs1);
Always returns -1
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21819918
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
 
LVL 5

Expert Comment

by:Alex-w474
ID: 21820330
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
 
LVL 5

Accepted Solution

by:
Alex-w474 earned 50 total points
ID: 21820333
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now