Re: new php script and sqlite

From: Date: Wed, 09 Sep 2009 19:57:18 +0000
Subject: Re: new php script and sqlite
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-297844@lists.php.net to get a copy of this message
> I was under the impression that sqlite2 was supported widely by PHP, > but sqlite3 seems only to be enabled on php 5.3.0 by default. > > My concern now is actually that users may find that their hosting > service providers don't provide sqlite3 out of the box. PDO seems to support both versions: http://us.php.net/manual/en/ref.pdo-sqlite.connection.php So if it's practical to restrict yourself to features that are available in both versions, you could probably do something like this: $db_file = '<filename>'; $dbh = null; try {   // prefer sqlite3 if available   $dbh = new PDO('sqlite:$db_file'); } catch (PDOException $e) {    // verify that error occurred because sqlite3 is not supported    try {        $dbh = new PDO('sqlite2:$db_file');    } catch (PDOException $e) {        // bail out gracefully    } } Ben

« previous php.general (#297844) next »