Search code examples
phpsqlitepdo

How to check which version of SQLite PDO use?


I used this code before I move to PDO:

    if (class_exists('SQLiteDatabase')) {
        return 'jargon.db';
    } else if (class_exists('SQLite3')) {
        return 'jargon3.db';
    } else {
        throw new Exception('SQLite not installed');
    }

How can I do the same using PDO


Solution

  • To check SQLite version you can use following code:

    $dbh = new PDO('sqlite::memory:');
    print_r("SQLite version " . $dbh->query('select sqlite_version()')->fetch()[0]);
    $dbh = null;