Creating new SQLite DBs with PDO

11,287

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.

Share:
11,287
Alix Axel
Author by

Alix Axel

If you need to, you can contact me at: alix [dot] axel [at] gmail [dot] com. I'm #SOreadytohelp Some of my GitHub repositories: phunction, a minimalistic PHP HMVC Framework. halBox, bash script to bootstrap Debian/Ubuntu servers. ArrestDB, RESTful API for SQLite, MySQL and PostgreSQL databases. genex.js, Genex module for Node.js. If you know how to work with regexes, have a look at http://namegrep.com/. ;)

Updated on June 07, 2022

Comments

  • Alix Axel
    Alix Axel almost 2 years

    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?

  • Alix Axel
    Alix Axel over 14 years
    Thanks, I didn't knew that. Also, is there a way to specify the database file permissions (chmod) upon creation?
  • Tor Valamo
    Tor Valamo over 14 years
    No, but the default is 666, I think. And so you can change it after you've created it and closed the connection. The directory where it's created needs to be writable though.