简体   繁体   中英

Fetch Number of Rows in a SQLite3 query

Can someone explain how SQLite3 is used to give the number of rows found in a query?

mysql has mysql_num_rows and SQLite2 has a similar function but someone in SQLite3 development seems to have forgotten to add that function.

The examples that I have seen here and on other sites do not answer the question but instead only create more questions.

SO...

I have a query like $queryStr = $d->query("SELECT * FROM visitors WHERE uid='{$userid}' AND account='active';");

what I want to know is how do I find out how many results are in $queryStr

I am not looking for the number of rows in the database, just the number of rows in the "query results"

SQLite computes query results on the fly (because this is more efficient for an embedded database where there is no network communication).

Therefore, it is not possible to find out how many records a query returns without actually stepping through all those records.

You should, if at all possible, structure your algorithm so that you do not need to know the number of records before you have read them. Otherwise, you have to execute a separate query that uses SELECT COUNT(*) to return the number of records, like this:

$countQuery = $d->query("SELECT COUNT(*) FROM visitors WHERE uid='{$userid}' AND account='active';");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM