如何确定PHP中一个SQLite 2查询中受影响的行数?

时间:2021-05-24 09:21:16

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:

我正在用PHP 5编写一个应用程序。我想删除SQLite v2数据库文件中的一些行。我正在做这样的事情:

$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?

如何知道这个查询影响了多少行?我删除了多少行?

2 个解决方案

#1


7  

The PHP function sqlite_changes() does this for you.

PHP函数sqlite_changes()为您实现了这一点。

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

返回最近针对dbhandle数据库句柄执行的SQL语句所更改的行数。

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();

#2


0  

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

我建议使用PDO和PDO:exec,它返回受影响的行数。(如果使用的是准备好的语句,则使用rowCount。)

#1


7  

The PHP function sqlite_changes() does this for you.

PHP函数sqlite_changes()为您实现了这一点。

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

返回最近针对dbhandle数据库句柄执行的SQL语句所更改的行数。

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();

#2


0  

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

我建议使用PDO和PDO:exec,它返回受影响的行数。(如果使用的是准备好的语句,则使用rowCount。)