Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating new SQLite DBs with PDO

I want to provide a setup feature in my next project and I'm wondering if it's possible to create a SQLite 3 database from scratch with PDO or I'm just stuck at connecting to existing databases via DSN?

If it isn't possible with PDO is there any way to create a new DB via PHP?

like image 672
Alix Axel Avatar asked Dec 12 '09 15:12

Alix Axel


People also ask

Does PDO work with SQLite?

PDO (PHP Data Objects) abstracts database access and enables you to create code that can handle different types of databases. One of the database types that PDO supports is SQLite.

What is PDO SQLite?

PDO_SQLITE is a driver that implements the PHP Data Objects (PDO) interface to enable access to SQLite 3 databases. Note: PDO_SQLITE allows using strings apart from streams together with PDO::PARAM_LOB .

How do I create a SQLite query database?

To create a new database in SQLite you need to specify databases when opening SQLite, or open an existing file using . open . You can use the . database command to see a list of existing databases.


1 Answers

A new sqlite database is created when you open a connection to one that doesn't exist. You can just check if the file exists, and then if it doesn't, then just create a new database connection and insert the tables.

like image 181
Tor Valamo Avatar answered Oct 08 '22 06:10

Tor Valamo