SQLite is a lightweight database that does not require a separate server, and is ideal for small applications, testing, and prototyping. PHP provides an interface for interacting with SQLite through the PDO_SQLITE extension. In this article, we will look at how to enable this extension on your server.
What is PDO?
PDO (PHP Data Objects) is a universal interface for working with databases in PHP. It provides the same API for working with different databases, making your code more portable.
Installing the required packages
PDO and PDO_SQLITE are usually enabled in standard PHP installations. However, depending on your server configuration, they may be disabled.
For Debian/Ubuntu:
Install the packages with the following command:
sudo apt-get update sudo apt-get install php-pdo php-sqlite3

Modifying the php.ini file
For PDO_SQLITE to work, you need to make sure that the appropriate extensions are enabled in php.ini
.
- Open your file
php.ini
:Find the location of yourphp.ini
using the command:
php --ini
- Make sure the following lines exist and are not commented out (that is, there is nothing before them).
;
)
extension=pdo.so extension=pdo_sqlite.so
Restarting the web server
After making changes, you need to restart your web server:
- Apache:
sudo service apache2 restart
- Nginx (Please note that PHP may be responsible for
php-fpm
)
sudo service nginx restart sudo service php-fpm restart
Checking the installation
Create a simple PHP file, for example info.php
, with the following contents:
<?php
phpinfo();
?>
Then open this file in your web browser. In the PDO and/or SQLite section you should see information about PDO_SQLITE
.
Using PDO_SQLITE
Once the extension has been successfully enabled, you can start using PDO to work with SQLite:
query('SELECT * FROM table_name'); foreach ($result as $row) { echo $row['column_name']; } ?>
Conclusion
You now have the PDO_SQLITE extension enabled and working on your server. This gives you the flexibility and power of an object-oriented interface for working with SQLite databases in PHP.