tags:

views:

401

answers:

2

currently I am using:

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

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

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

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

Can anybody help please?

+2  A: 

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.

Felix Kling
many thanks for this!
Remover
A: 

thanks for your solution

ary