本文介绍了在PHP中使用SQlite3如何计算结果集中的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在使用:

$result = new SQLite3(sprintf("users/USERIDS_DB.sqlite"));

$numRows = $result->exec ("SELECT count(*) FROM USERIDS");

echo sprintf("the number of rows are: %d", $numRows);

但是结果是1当它应该是6(使用firefox sqlite3 addon创建的行数)

but the result is 1 when it should be 6 (the number of rows I created using firefox sqlite3 addon)

任何人都可以帮助吗?

推荐答案

href =http://www.php.net/manual/en/sqlite3.exec.php =nofollow noreferrer>文档:

From the documentation:

执行 / strong>查询。

Executes a result-less query against a given database.

此方法返回布尔值,而不是结果集。当将 true 转换为整数时,它将变为 1

This methods returns a boolean, not a result set. When you convert true to an integer it will become 1.

您应该使用。示例(未测试):

You should use SQLite3::query(). Example (untested):

$rows = $result->query("SELECT COUNT(*) as count FROM USERIDS");
$row = $rows->fetchArray();
$numRows = $row['count'];






Btw,命名SQLite3类的实例 $ result 可能会误导(特别是在DB环境中)。我会把它叫做 $ db $ connection


Btw, naming the instance of the SQLite3 class $result can be misleading (especially in a DB environment). I would call it $db or $connection.

这篇关于在PHP中使用SQlite3如何计算结果集中的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:16
查看更多