Reply to Re: Connecting to SQLite3 database from PHP 5.25

Your name:

Reply:


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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация