Note that the SQLITE3_OPEN_READONLY flag cannot be combined with the SQLITE3_OPEN_CREATE flag. If you combine both of these flags, a rather unhelpful "Unable to open database: out of memory" exception will be thrown.(PHP 5 >= 5.3.0, PHP 7, PHP 8)
SQLite3::__construct — Yeni bir SQLite3 nesnesini ilklendirdikten sonra bir SQLite veritabanını açar
$dosya, int $seçenekler = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $anahtar = "")
Yeni bir SQLite3 nesnesini ilklendirdikten sonra
dosya ile belirtilen SQLite veritabanına bir
bağlantı açar. Eğer veritabanı şifreliyse anahtar
ile şifresini çözmeye çalışır.
dosya
SQLite veritabanını içeren dosyanın yolu veya veritabanını bellek
içinde kullanmak için :memory:.
dosya olarak boş bir dize verilmişse, disk
üzerinde geçici olarak özel bir veritabanı oluşturulur. Bu özel
veritabanı, veritabanı bağlantısı kapanır kapanmaz otomatik olarak
silinir.
seçenekler
SQLite veritabanının nasıl açılacağını belirleyen seçimlik seçenekler.
Öntanımlı olarak, SQLITE3_OPEN_READWRITE |
SQLITE3_OPEN_CREATE kullanılır.
SQLITE3_OPEN_READONLY: Veritabanı okumak için
açılır.
SQLITE3_OPEN_READWRITE: Veritabanı hem okumak
hem de yazmak için açılır.
SQLITE3_OPEN_CREATE: Veritabanı yoksa
oluşturulur.
anahtarSQLite veritabanını şifrelemek/şifresini çözmek için kullanılan şifreleme anahtarı. SQLite şifreleme modülü kurulu değilse, bu bağımsız değişkenin etkisi yoktur.
Başarısızlık durumunda bir Exception yavrulanır.
| Sürüm: | Açıklama |
|---|---|
| 7.0.10 |
Disk üzerinde geçici olarak oluşturulacak özel bir veritabanı
kullanmak için dosya artık boş dize olabiliyor.
|
Örnek 1 - SQLite3::__construct() örneği
<?php
$db = new SQLite3('mysqlitedb.db');
$db->exec('CREATE TABLE foo (bar TEXT)');
$db->exec("INSERT INTO foo (bar) VALUES ('Bu bir denemedir.')");
$result = $db->query('SELECT bar FROM foo');
var_dump($result->fetchArray());
?>Note that the SQLITE3_OPEN_READONLY flag cannot be combined with the SQLITE3_OPEN_CREATE flag. If you combine both of these flags, a rather unhelpful "Unable to open database: out of memory" exception will be thrown.$encryption_key and all encryption features will be enabled only if the SQLite encryption module is installed. It's a proprietary, costly module. So if it's not present, supplying an encryption key will have absolutely no effect.This constructor offers no built-in way to set the file's protection, for example, to allow group-wide read-write access to other users belonging to the www-data group. It is possible to create an empty file, then use chmod() to set the protection as needed. You can use code like this to create the file so it is group-writable (0664).
<?php
if ( !file_exists( $path ) ) {
touch( $path );
chmod( $path, 0664 );
}
$sqlite_handle = new SQLite3( $path, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, '' );
?>
SQLite3 uses the same file protection on the .sqlite file you create for its other files, the .,sqlite-shm and .sqlite-wal files.