Luís Jesus
Luís Jesus

Reputation: 1678

SQLite3 equivalent to mysql_num_rows

What's the equivalent in SQLite3 to mysql_num_rows? I know SQLite had a similar function call. What I'm doing in PHP is doing a for while fetching an array from the query and counting a variable but I don't like it very much.

Upvotes: 2

Views: 3664

Answers (2)

malko
malko

Reputation: 2382

You have a changes method that will offer the num rows/affected rows functionality for update/delete methods. For select type queries, you can count the result set or effectively make a second request that will count the result of your previous query (will cost more time to your application). For a "select users where firstname = 'john'" this should look something like this:

SELECT count(*) FROM ( select users where firstname = 'john' ) as tmp;

But it will cost you an extra query and i'm pretty sure that counting the returned result set will be more efficient.

Upvotes: 3

The87Boy
The87Boy

Reputation: 887

What about the SQL-query called COUNT?

Upvotes: -2

Related Questions