I have a SELECT query that get one or more rows from a large table. The script must do different things if the result is either 0, 1 or 2 and more rows. I'm using PDO and is has no function like mysql_num_rows() ... what must I do then?
I thought about running a second query with COUNT(*), but is that efficient? Or is it better to do a count(fetchAll())?
Does anybody know the best way to do it?
/Asger
PDO, fetched rows and the fastest way...
Moderator: General Moderators
-
asgerhallas
- Forum Commoner
- Posts: 80
- Joined: Tue Mar 14, 2006 11:11 am
- Location: Århus, Denmark
-
asgerhallas
- Forum Commoner
- Posts: 80
- Joined: Tue Mar 14, 2006 11:11 am
- Location: Århus, Denmark
Ok, thanks!
Does that COUNT(*) need to be in another query, or is there a smart way to have it as a row in the same query?
I've tried this:
But it wants the GROUP BY in it - and I can't find out what to GROUP BY - any idea?
Does that COUNT(*) need to be in another query, or is there a smart way to have it as a row in the same query?
I've tried this:
Code: Select all
SELECT *, COUNT(*) cnt FROM table WHERE name='somename'-
asgerhallas
- Forum Commoner
- Posts: 80
- Joined: Tue Mar 14, 2006 11:11 am
- Location: Århus, Denmark