Create an 'unconnected' SQLite instance
Ive just discovered the convenience of having SQLite at my disposal. However, the 开发者_Python百科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?
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.
精彩评论