|
Posted by Oliver Grδtz on 12/07/07 15:23
John schrieb:
> Let me try to find the right line to point PHP to the right place. In the
> meantime it still is very problematic to get something out of the database
> on the webbrowsers screen. PHP let's me connect to the database but after
> that it is a no go. It return an errormessage that the database is encrypted
> or not a database at all. Seems an issue between the latetst SQLite version
> and PHP.
To check the type:
public static function checkFileType($path)
{
if (!file_exists($path)) return 'not found';
$f=fopen($path,'r');
if (!$f)
{
return 'locked';
}
$test=fread($f,44);
fclose($f);
if(strstr($test,'** This file contains an SQLite 2.1 database'))
return 'sqlite2';
elseif(strstr($test,'SQLite format 3'))
return 'sqlite3';
else
return 'unknown';
}
Now you can use a switch() to use the right connection type. I use two
classes for the different connection types. The one for SQLite2 uses
$this->db = new SQLiteDatabase($dbFile,0666,$this->err);
The one for SQLite3 uses:
$this->db = new PDO('sqlite:'.$dbFile);
This objects are encapsulated in two connection classes that both
provide a compatible API to use one version of SQLite or the other.
But: This code is pretty old, in modern PHP you should be able to use
PDO for both versions of SQLite and to use "sqlite:" for version3 and
"sqlite2:" for version 2. This removes the need for an abstraction layer
for the two versions because now the API is PDO for both versions.
OLLi
--
Tom: "You are aware of our project?"
Vaughn: "We're aware you pay good money."
Tom: "We require quite a commitment."
Vaughn: "We require quite a payment."
[Alias 405]
[Back to original message]
|