Knowledge Base Overview
open basedir prohibits opening
Created: Last updated:
If you try to load an SQLite DB file and suddenly encounter this error "safe_mode/open_basedir prohibits opening" then you might have the same problem I had. In my case it took me almost 6 hours until I discovered the tiny little problem. It took so long because the error message is quite frankly one of these stupid cases where it leads you in a completely wrong direction.
Following are all the details about my case and the solution at the end.
Loading a SQLite db file
The SQLite database file I was loading was actually outside the regular base directory [adding insult to injure]. Ergo at first, the error made total sense until I discovered that I don't have any of these settings in place. Also because I use other database files without a hitch and they are actually also outside the basedir.
At some point it dawned on me that there must be a problem with the path for the db file. The path with the db filename acts as the database name in PDO for SQLite.
Actually, I was using the realpath() function to make sure that the path is properly formatted—which turned out to be my problem because I made two crucial mistakes in this case. First I did not care about the returned result and second I did not verify the path I sent to the realpath function.
The realpath() function not only formats the path it also verifies if the path is valid, i.e. if this directory or file exists. If not it returns a Boolean false value and that's what I got because I used a constant with a path that was wrong. I never realized and verified what I was passing as the value into the Zend_Config_Ini object as the dbname and in return to the Zend_Db factory method. For the longest time I was not aware that the db filename actually was a Boolean false value.
So, it turned out to be real simple my problem; although, the error message was totally wrong and led me into the wrong direction.
If you pass an empty or a non string value to PDO/SQLite you will get this "safe_mode/open_basedir prohibits opening" error.
Note that if you pass a string, which resembles somewhat of a directory but the file cannot be located, you will get an appropriate response which is usually "unable to open database file."