tags:

views:

1387

answers:

2

I'm writing an application in PHP 5. I want to delete some rows in a SQLite v2 database file. I'm doing something like this:

$sqliteConnection = new SQLiteDatabase('path/to/db');
$queryString = "DELETE FROM myTable WHERE status='not good'";
$result = $sqliteConnection->query($queryString);

how can I know how many rows were affected by this query? how many rows have I deleted?

+3  A: 

The PHP function sqlite_changes() does this for you.

Returns the numbers of rows that were changed by the most recent SQL statement executed against the dbhandle database handle.

Call it either in procedural-style:

echo 'Number of rows modified: ', sqlite_changes($sqliteConnection);

or in object-style:

echo 'Number of rows modified: ', $sqliteConnection->changes();
Tomalak
I'm voting you up instead of Owen simply because you did a more thorough job of explaining.
Jeff Hubbard
A: 

I'd recommend using PDO and PDO:exec, which returns the number of affected rows. (Or rowCount if you use a prepared statement.)

stesch