In memory sqlite has some limitations. The memory space could be the request, the session, but no way seems documented to share a base in memory among users.
For a request, open your base with the code
$pdo = new PDO( 'sqlite::memory:');
and your base will disapear on next request.
For session persistency
<?php
$pdo = new PDO(
'sqlite::memory:',
null,
null,
array(PDO::ATTR_PERSISTENT => true)
);
?>
PDO_SQLITE DSN
(PECL PDO_SQLITE >= 0.2.0)
PDO_SQLITE DSN — Verbindungen zu SQLite-Datenbanken aufbauen
Beschreibung
Der PDO_SQLITE-Data Source Name (DSN) setzt sich aus den folgenden Elementen zusammen:
- DSN-Präfix (SQLite 3)
-
Das DSN-Präfix ist
sqlite:.-
Um eine Datenbank auf dem Datenträger anzusprechen, wird ihr absolute Pfad an das DSN-Präfix angehängt.
-
Um eine Datenbank im Speicher zu erzeugen, wird :memory: an das DSN-Präfix angefügt.
-
- DSN-Präfix (SQLite 2)
-
Die SQLite-Erweiterung in PHP 5.1 stellt einen PDO-Treiber zur Verfügung, welcher den Zugriff auf und das Erstellen von SQLite2-Datenbanken unterstützt. Das versetzt Sie in die Lage, auf Datenbanken zu zugreifen, die Sie mit einer SQLite-Erweiterung in früheren PHP-Versionen erstellt haben.
Hinweis:
Der SQLite2-Treiber steht in PHP 5.1.x nur zur Verfügung, wenn Sie PDO und ext/sqlite aktiviert haben. Er ist zur Zeit nicht in PECL verfügbar.
Der DSN-Präfix, um eine Verbindung zu einer SQLite2-Datenbank aufzubauen ist
sqlite2:.-
Um eine Datenbank auf dem Datenträger anzusprechen, wird ihr absoluter Pfad an das DSN-Präfix angehängt.
-
Um eine Datenbank im Speicher zu erzeugen, wird :memory: an das DSN-Präfix angefügt.
-
Beispiele
Beispiel #1 PDO_SQLITE DSN Beispiele
Die folgenden Beispiele zeigen PDO_SQLITE DSN, die genutzt werden, um Verbindungen zu SQLite-Datenbanken aufzubauen:
sqlite:/opt/databases/mydb.sq3 sqlite::memory: sqlite2:/opt/databases/mydb.sq2 sqlite2::memory:
@ Fatmoon
That is correct. SQLite sometimes uses additional files in the same folder while writing to the DB. These files can sometimes be seen and usually contain the name of your DB and the word 'journal' in their filename.
Security wise, it might be a good idea to store the SQLite databases in a seperate folder to shield the rest from user www.
It seems that the directory that contains your sqlite database must be writeable by the web server. Making just the file writeable won't work.
Don't forget "extension=php_pdo_sqlite.dll" has to be enabled in php.ini (if you use xampp is will be disabled by default) .
