Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP CRUD Operations with PHP Project Setup Connecting to the Database

dolores fernandez
dolores fernandez
375 Points

Does the database HAVE TO be placed in the root folder? sqlite:".__DIR__."/the_database.db

On the first step for creating the database.db, we are using DIR to place it in our root folder of our project, does it have to be there? Could we just do "sqlite:the_database.db" ? I have tried with the Exception, but it seems alright, so I can't tell if it has to be placed in the root folder or we can place it wherever we want.

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Normally you'd put the file in the connections folder which is why you don't specify a file path with the file name. It indicates that your database is in the same folder as your connection file not necessarily the root folder. :-)

dolores fernandez
dolores fernandez
375 Points

Thank you! It sounds ridiculous but yesterday I spent many hours looking for that information and I ended up frustrated because I couldn't find that answer anywhere!

Just further to this question, does declaring the file path this way ensure that once your site is FTP'd up to the production server the database connection will still work?

Cheers Don :-)