Named Sqlite3 In Memory¶
By archtechx
<?php
$foo = new PDO('sqlite:file:foo?mode=memory&cache=shared');
// add some tables and rows to foo
$bar = new PDO('sqlite:file:bar?mode=memory&cache=shared');
// $bar remains totally independent
$foo2 = new PDO('sqlite:file:foo?mode=memory&cache=shared');
// $foo2 contains the EXACT SAME database as $foo
Sqlite3 allows the creation of memory databases: the database is not stored on the disk, but in memory. This is good for temporary data, that requires some SQL features.
Then, by default, every instantiation of a Sqlite3 memory database provides the same database. Then, when using the command sqlite:file:foo:?mode=memory&cache=shared, the memory database gets a name, and it is now possible to have distinct sqlite3 instances.
See Also¶
PHP Features¶
Last updated: 14 July 2026