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 PHP & Databases with PDO PDO Queries & Results Queries with PDO

Jeffrey Cheong
Jeffrey Cheong
5,653 Points

Error on preview page when trying to access the database

when I try to preview the database var_dump I get this error

SQLSTATE[HY000] [14] unable to open database file

Anyone got a solution for that?

Hi there - not sure if this is pertinent to your situation, but I found this on Google for you and I hope it helps:

When you're testing your PHP applications with SQLite you might bump into a problem when using PDOthat states "SQLSTATE[HY000]: General error: 14 unable to open database file". When using Zend Framework 2, you might only get the InvalidQueryException "Statement could not be executed", for which I've made a pull request on Github to make it more clear what's going on. The problem is about permissions. For SQLite it's not enough to make the database file writeable for the web server user, but also the directory this file is in. I found the solution on StackOverflow, thanks to Austin Hyde for giving the answer that pointed me in the final path to the solution. In order to fix this issue I changed the group of the directory and db file to "www-data", the group my web server (Apache) was running on, and made them writeable for the group. $ cd /path/to/application $ chgrp www-data data/db $ chgrp www-data data/db/application-test.db $ chmod g+w data/db $ chmod g+w data/db/application-test.db Hope to help other developers using SQLite in their development save a lot of time searching for something this trivial.

Jeffrey Cheong
Jeffrey Cheong
5,653 Points

Hi Matt,

I'm kind of confused as to how I would go about changing the group directory, it doesn't seem to work for me to type in the commands in the console and I am wondering if other people had this same problem cause I can't properly continue after the second video of this first section of the PHP & Databases track.

The full error I am getting when attempting to var_dump and preview is:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [14] unable to open database file' in /home/treehouse/workspace/index.php:6 Stack trace: #0 /home/treehouse/workspace/index.php(6): PDO->__construct('sqlite:/databas...') #1 {main} thrown in /home/treehouse/workspace/index.php on line 6

1 Answer

if you use "treehouse workspaces" delete it and launch it again from last video ... it will work .. i had this problem .. and it is work for me :)