Using SQlite3 in PHP how to count the number of rows in a result set?
From the documentation:
public bool SQLite3::exec ( string $query )
Executes a result-less query against a given database.
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, naming the instance of the SQLite3 class $result
can be misleading (especially in a DB environment). I would call it $db
or $connection
.