I have a sqlite database that I did not create myself but from a trusted source that resides in a folder called ‘database’. This folder is stored inside another folder in my localhost folder.
However, the error I am receiving when i’m trying to run a simple application is this:
SQLSTATE[HY000] [14] unable to open database file
Does anyone know what this is referring to? I doubt it’s my code but here it is:
pdo.class.php
class pdoClass {
// private statics to hold the connection
private static $dbConnection = null;
// make the next 2 functions private to prevent normal
// class instantiation
private function __construct() {
}
private function __clone() {
}
public static function getConnection() {
// if there isn't a connection already then create one
if ( !self::$dbConnection ) {
try {
self::$dbConnection = new PDO('sqlite:/database/library.sqlite');
self::$dbConnection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e ) {
echo $e->getMessage();
}
}
// return the connection
return self::$dbConnection;
}
}
?>
This is then referenced by another class that requires this one to output any sql data into XML format. Any help to why my sqlite database doesn’t seem to want to open is greatly appreciated (the file is set to read & write).
Thanks
Tim
The code looks good, my feeling is that the problem is with path /database/library.sqlite
This is an absolute path. So il will search database directory in the root directory of the filesystem is that what you want? or maybe databse is a directory a the same level of your running script? in that case sqlite:database/library.sqlite’