简体   繁体   English

在SQLite3查询中获取行数

[英]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? 有人可以解释如何使用SQLite3给出查询中找到的行数吗?

mysql has mysql_num_rows and SQLite2 has a similar function but someone in SQLite3 development seems to have forgotten to add that function. mysql具有mysql_num_rows,而SQLite2具有类似的功能,但是SQLite3开发中的某个人似乎忘记了添加该功能。

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';"); 我有一个查询,如$ 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 我想知道的是如何找出$ 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). SQLite可以即时计算查询结果(因为对于没有网络通信的嵌入式数据库,此方法效率更高)。

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: 否则,您必须执行一个单独的查询,该查询使用SELECT COUNT(*)返回记录数,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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