Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you delete an in-memory SQLite database with PHP PDO?

Tags:

php

sqlite

pdo

When I create a SQLite memory database - how do I delete it when I'm finished? Is it automatically released when the script ends and closes the connection?

$pdo = new PDO('sqlite::memory:');
like image 878
Xeoncross Avatar asked Feb 21 '12 20:02

Xeoncross


People also ask

How do I delete an SQLite database?

To create a new database, just do sqlite_open() or from the command line sqlite3 databasefilename . To drop a database, delete the file. An embedded db engine means for me a file based database as seen with sqlite, so deleting the db. db file will drop the db.

Does PDO work with SQLite?

The PDO_SQLITE extension provides the PDO driver for the SQLite 3 library. It supports standard PDO interfaces, and also custom methods for creating SQL functions and aggregates using PHP. In this section, we will walk you through the steps of using PDO to access SQLite databases.

How do I remove something from a table in SQLite?

sqlite> DELETE FROM table_name; Following is the basic syntax of DROP TABLE. sqlite> DROP TABLE table_name; If you are using DELETE TABLE command to delete all the records, it is recommended to use VACUUM command to clear unused space.

Is SQLite stored in memory?

SQLite in-memory databases are databases stored entirely in memory, not on disk. Use the special data source filename :memory: to create an in-memory database. When the connection is closed, the database is deleted.


2 Answers

The most common way to force an SQLite database to exist purely in memory is to open the database using the special filename ":memory:"... ...When this is done, no disk file is opened. Instead, a new database is created purely in memory. The database ceases to exist as soon as the database connection is closed. Every :memory: database is distinct from every other. So, opening two database connections each with the filename ":memory:" will create two independent in-memory databases. - SQLite

like image 75
Xeoncross Avatar answered Oct 02 '22 13:10

Xeoncross


Yes, that's what happens.

like image 25
zerkms Avatar answered Oct 02 '22 13:10

zerkms