Use extension_loaded() or PDO::getAvailableDrivers() to verify the SQLite interfaces available in the current PHP runtime.
<?php
$pdoSqlite = in_array('sqlite', PDO::getAvailableDrivers(), true);
$sqlite3 = extension_loaded('sqlite3');
echo 'PDO_SQLITE: ' . ($pdoSqlite ? 'available' : 'not available') . '
';
echo 'SQLite3: ' . ($sqlite3 ? 'available' : 'not available');
?><?php
echo phpinfo();
?>
var_dump(PDO::getAvailableDrivers());
By using PDO::getAvailableDrivers() we can get an array of available PDO drivers, so we can use in_array() to check the presence of SQLite inside the array and if-else to display appropriate message to user.
<?php
if (!in_array("sqlite",PDO::getAvailableDrivers(),TRUE))
{
throw new PDOException ("Cannot work without a proper database setting up");
}else{
echo "<font color='green'>Database setup is OK</font>";
}
?>
php_sqlite3.dll inside your php.ini file.
$ver_dtl = SQLite3::version();
echo $ver_dtl['versionString'] . "<br>";
echo $ver_dtl['versionNumber'] . "<br>";
var_dump($ver_dtl);
Output is here ( may change based on your installation )
3.8.10.2
3008010
array(2) { ["versionString"]=> string(8) "3.8.10.2" ["versionNumber"]=> int(3008010) }
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.