Re: new php script and sqlite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux