I have installed SQLite on my UNIX system, and am planning on accessing it from PHP. However, the database is created in the directory I initialize it in, and if a script runs in a different directory a new database is created in the same directory.
Is there an option for SQLite (or the PHP wrappers) to create the databases in one location, and have those databases accessible just by name outside of that directory?
Ideally, I’d like to be able to do something like $db=new SQLiteDatabase("db.test"); in any directory and have it reference the same database, if that makes sense.
In order to always use the same database (which, afterall, is only a file), you’ll have to use an absolute path.
Instead of using
'db.test', which is relative to the current directory, you’ll have to use something like'/home/user/development/application/db.test'.Note the
/at the beginning of the path, which makes it absolute.Of course, up to you to adapt this to your needs 🙂
A good possibility, to not put a fully hard-coded path in your code, would be to use
dirname(__FILE__)in one of your PHP files, to get the full absolute path to the directory containing that file, and build up from there, to get to your database’s file.