Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 10th, 2002, 08:09 AM
rowshi's Avatar
rowshi rowshi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 9 rowshi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to rowshi
Question "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.)

Reply With Quote
  #2  
Old December 10th, 2002, 08:51 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 693 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 4 h 5 m 20 sec
Reputation Power: 25
I have also wrote a cross-db class. I would recommend sticking to the basics. You really only need about 5 functions that will work with any DB.

I really don't see the point of doing a count, It has to fetch all the rows and is inefficient, I would always do a select count(*)anyways.

So what I believe to be the functions necessary are:
1. open - connect to db and return handle
2. execute - parse and execute query, return cursor
3. fetch - move cursor forward
4. getColumnResult - get value of column from cursor
5. close - close db

Reply With Quote
  #3  
Old December 10th, 2002, 09:13 AM
rowshi's Avatar
rowshi rowshi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 9 rowshi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to rowshi
yeah, I'm working around the problem by doing a
PHP Code:
 SELECT count(*) FROM tablename 
and storing that.

What I'm trying to work toward is full functionality comprable to the built-in MySQL functions. It's probably a pipe dream in this case.

That and using a SELECT count() is more to write. Then again, it does run quicker.

That's why I want a one-liner that's built into the Jet DB Engine.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > "num_rows" in MS Access

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap