tags:

views:

26

answers:

1

Ive just discovered the convenience of having SQLite at my disposal. However, the convenience factor is causing a small problem for me and the way I've set up my database connection objects. In order to provide some semblance of database neutrality and abstraction, I've created a DatabaseUtil.php factory class - the main method, getDBConnection is accessed statically and is meant to return an instance to a database based on the DB type specified in my properties file.

The issue with SQLite is simply that there does not seem to be a way to create an instance of SQLite that is independent of a connected database. This isn't a huge problem per se - it just requires me to pass in an additional argument for SQLite database connections and requires me to know before hand what database I want to connect to.

When creating a mysql connection, a database can be selected later - for example:

$connection = mysql_connect('localhost');
mysql_select_db('exampledb', $connection);

Is there a way to obtain an SQLite connection object without connecting to a specific DB?

+1  A: 

In short, no.

In a bit longer, consider this: with MySQL (and friends), you can establish a connection to a database server without selecting a particular database to work with. However, since SQLite doesn't need any such connection, that step doesn't make any sense.

David Wolever
I see - I suspected as much but was holding out for hope :0) In the end it doesn't matter all that much - especially considering I was only planning to use SQLite for unit testing and maybe runtime configuration. Thank you!
Matt1776
Glad I could help.
David Wolever