PHP Velho Oeste 2024

sqlite_changes

SQLiteDatabase->changes

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

sqlite_changes -- SQLiteDatabase->changesEn son SQL deyiminin değiştirdiği satır sayısını döndürür

Açıklama

sqlite_changes ( resource $db ) : int

Nesne yönelimli kullanım

changes ( void ) : int

En son SQL deyiminin db veritabanında değiştirdiği satır sayısını döndürür.

Değiştirgeler

db

SQLite Veritabanı özkaynağı. Yordamsal kullanımda sqlite_open() işlevi tarafından döndürülür. Nesne yönelimli kullanımda bu değiştirgeye gerek yoktur.

Dönen Değerler

Değişen satır sayısı.

Örnekler

Örnek 1 - Yordamsal kullanım örneği

<?php
$dbhandle 
sqlite_open('mysqlitedb');
$query sqlite_query($dbhandle,
        
"UPDATE users SET email='jDoe@example.com' WHERE username='jDoe'");
if (!
$query) {
    exit(
'Sorguda hata.');
} else {
    echo 
'Değişen satır sayısı: 'sqlite_changes($dbhandle);
}
?>

Örnek 2 - Nesne yönelimli kullanım örneği

<?php
$dbhandle 
= new SQLiteDatabase('mysqlitedb');
$query $dbhandle->query(
        
"UPDATE users SET email='jDoe@example.com' WHERE username='jDoe'");
if (!
$query) {
    exit(
'Sorguda hata.');
} else {
    echo 
'Değişen satır sayısı: '$dbhandle->changes();
}
?>

Ayrıca Bakınız

  • sqlite_open() - Bir SQLite veritabanı için bir tanıtıcı açar, veritabanı mevcut değilse oluşturur

add a note add a note

User Contributed Notes 2 notes

up
0
bermi ferrer:at-akelos dotCom
18 years ago
When counting deleted records from the database, I realized that sqlite_changes() will return 0 if you are deleting all the records without including a WHERE clause.

So after "DELETE FROM users" sqlite_open() will print 0 even if rows where deleted, but if you use "DELETE FROM users WHERE 1" you will get the right result.

I had this problem on versions 5.0.4 and 4.4.0 under Windows servers.
up
-1
jazz at funkynerd dot com
14 years ago
When executing DELETEs, I found that adding an always true WHERE clause returns the number of rows deleted.

eg:  "DELETE FROM my_table WHERE 1"  will delete all the rows and sqlite_changes() will return the correct number of rows deleted.
To Top