• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • SQLite3::changes()

    (PHP 5 >= 5.3.0, PHP 7)

    Returns the number of database rows that were changed(or inserted or deleted)by the most recent SQL statement

    说明

    publicSQLite3::changes(void): int

    Returns the number of database rows that were changed(or inserted or deleted)by the most recent SQL statement.

    参数

    此函数没有参数。

    返回值

    Returns an integer value corresponding to the number of database rows changed(or inserted or deleted)by the most recent SQL statement.

    范例

    SQLite3::changes() example

    <?php
    $db = new SQLite3('mysqlitedb.db');
    $query = $db->exec('UPDATE counter SET views=0 WHERE page="test"');
    if ($query) {
        echo 'Number of rows modified: ', $db->changes();
    }
    ?>
    
    There is an issue that may be meant or not, but in my case is annoying. If you have have a schema like the following:
    [code]
    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
    );
    [/code]
    When you try to delete a parent row (delete from parent where parent.id=?) it deletes all the childs referenced to this parent, but the method SQLite3::changes() is still returning 1, as if it only have deleted the parent.
    It seems, that this method doesn't report the affected rows properly, when using with savepoints or a transaction.