简体   繁体   English

Sqlite3如何在不读取所有行的情况下获取表中的行数?

[英]Sqlite3 How to get number of rows in table without reading all the rows?

Can some shed some light on hoe to get the number of rows (using php) in a table without actually having to read all the rows? 可以在不真正读取所有行的情况下阐明一些问题以获取表中的行数(使用php)吗? I am using squlite to log data periodically and need to know the table row count before I actually access specific data? 我正在使用squlite定期记录数据,并且在我实际访问特定数据之前需要了解表行数吗?

Apart from reading all rows and incrementing a counter, I cannot seem to work out how to do this quickly (it's a large database) rather simple requirement? 除了读取所有行并增加计数器外,我似乎无法弄清楚如何快速执行此操作(这是一个大型数据库),但要求很简单? I have tried the following php code but it only returns a boolean response rather that the actual number of rows? 我尝试了以下php代码,但它仅返回布尔响应,而不是实际的行数?

$result = $db->query('SELECT count(*) FROM mdata');

Normally the SELECT statement will also return the data object (if there is any?) 通常,SELECT语句还将返回数据对象(如果有)?

Just use 只需使用

LIMIT 1

That should work!! 那应该工作! It Limits the result to ONLY look at 1 row!! 它将结果限制为只能查看1行!!

如果您有记录集,则可以通过mysql_num_rows(#Record Set#)获得编号或记录。

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

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