$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.
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
SQLite3::__construct — Instancia un objeto SQLite3 y abre la base de datos SQLite 3
$filename
, int $flags
= SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $encryptionKey
= "")Inicializa un objeto SQLite3 y abre una conexión a la base de datos SQLite 3. Si el cifrado ha sido incluido durante la compilación, entonces esta función intentará utilizar la clave correspondiente.
filename
Ruta hacia la base de datos SQLite, o :memory:
para utilizar
la base de datos que se encuentra en la memoria RAM.
Si filename
es una cadena vacía, se creará una base de
datos temporal privada en el disco. Esta base de datos
privada será automáticamente eliminada tan pronto como la conexión de la base de
datos sea cerrada.
flags
Bandera opcional utilizada para determinar la manera de apertura de la
base de datos SQLite. Por omisión, la apertura se efectúa utilizando
SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE
.
SQLITE3_OPEN_READONLY
: Abre la base de datos
en modo solo lectura.
SQLITE3_OPEN_READWRITE
: Abre la base de datos
en modo lectura y escritura.
SQLITE3_OPEN_CREATE
: Crea la base de datos si
no existe.
encryptionKey
Una clave de cifrado opcional, a utilizar durante el cifrado/descifrado de la base de datos SQLite. Si el módulo SQLite no está instalado, este parámetro no tendrá ningún efecto.
Lanza una Exception en caso de error.
Versión | Descripción |
---|---|
7.0.10 |
El filename puede ahora estar vacío para utilizar una base de datos privada, temporal en disco.
|
Ejemplo #1 Ejemplo con SQLite3::__construct()
<?php
$db = new SQLite3('mysqlitedb.db');
$db->exec('CREATE TABLE foo (bar TEXT)');
$db->exec("INSERT INTO foo (bar) VALUES ('This is a test')");
$result = $db->query('SELECT bar FROM foo');
var_dump($result->fetchArray());
?>
$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.
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.