简体   繁体   English

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

[英]how can I determine the number of affected rows in a SQLite 2 query in PHP

I'm writing an application in PHP 5. I want to delete some rows in a SQLite v2 database file. 我正在用PHP 5编写一个应用程序。我想删除SQLite v2数据库文件中的一些行。 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? 我删除了多少行?

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

I'd recommend using PDO and PDO:exec , which returns the number of affected rows. 我建议使用PDOPDO:exec ,它返回受影响的行数。 (Or rowCount if you use a prepared statement.) (如果使用准备语句,则为rowCount 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM