PHP Conference Japan 2024

SQLite3::changes

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

SQLite3::changes 傳回最近一次 SQL 陳述式所變更(或插入或刪除)的資料庫列數

說明

public SQLite3::changes(): int

傳回最近一次 SQL 陳述式所變更(或插入或刪除)的資料庫列數。

參數

此函式沒有參數。

傳回值

傳回一個 int 值,對應於最近一次 SQL 陳述式所變更(或插入或刪除)的資料庫列數。

範例

範例 #1 SQLite3::changes() 範例

<?php
$db
= new SQLite3('mysqlitedb.db');

$query = $db->exec('UPDATE counter SET views=0 WHERE page="test"');
if (
$query) {
echo
'修改的列數:', $db->changes();
}
?>

新增註記

使用者貢獻的註記 1 則註記

4
teclado at tandex dot com
9 年前
有一個問題可能是有意的或無意的,但在我的情況下很惱人。如果您有以下的 schema

[程式碼]
pragma foreign_key = on;
create table parent (
id integer,
a varchar,
primary key (id asc)
);
create table child (
id integer,
b varchar,
a integer,
primary key (id asc),
foreign key (a) references a (id) on delete cascade on update cascade
);
[/程式碼]

當您嘗試刪除一個父列 (delete from parent where parent.id=?) 時,它會刪除所有參考此父項的子項,但 SQLite3::changes() 方法仍然返回 1,就好像它只刪除了父項一樣。
To Top