18

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?

2
  • Why didn't you supply the sqlite file as well? Commented Dec 12, 2009 at 15:35
  • 2
    I can do that, but I want to know if there is a way to create DB by running SQL statements like CREATE DATABASE, CREATE TABLE and so on. Commented Dec 12, 2009 at 15:38

1 Answer 1

24

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I didn't knew that. Also, is there a way to specify the database file permissions (chmod) upon creation?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.