
December 10th, 2002, 08:09 AM
|
 |
Registered User
|
|
Join Date: Dec 2002
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
"num_rows" in MS Access
I am foolishly writing my own Database Abstraction Layer for both Access and MySQL.
MySQL is quite easy, as most my functions parallel those built into PHP.
MS Access is a different story. Particularly a "num_rows" function to count the number of rows returned by a SQL query.
Before you tell me to use ODBC, I'm not using it! I'm using a COM object instead so I can keep the database and the PHP together. I want to be able to connect to my Access DB even if I don't have access on the server to make an ODBC connection. So the simple and easy solution is out.
My current solution works fine when the query returns 2 or more rows. Basically it runs through a while loop and increments a counter. The problem is what happens if the query returns one or no rows. Here's an exerpt from the code:
PHP Code:
function num_rows () {
if (is_object($this->COM_OBJ)) {
if (is_object($this->CURSOR)) {
$this->CURSOR->movefirst();
$counter = 0;
while (!($this->CURSOR->EOF)){
$counter++;
$this->CURSOR->movenext();
}
$this->CURSOR->movefirst();
return $counter;
} else {
// There is no cursor from a query.
// Make sure to execute an SQL query using $obj->execute("sql_query)
$this->error ("There is no cursor from a SQL query", 1);
}
} else {
// There is no database connection object.
// Make sure to run $obj->connect("filename") before trying to collect data from a query.
$this->error ("The database connection object is missing.", 1);
}
} // END function num_rows ()
Anyone out there have any good ideas how to do this better?
Anyone know the way to get the number of rows directly from the Jet Engine through PHP? (That's the ideal solution.)
|