Here we will see how to configure Codeigniter 3.1 and SQLite3 in Windows environment. You can choose any database from a number of supported databases in Codeigniter framework. One of them is SQLite, which is in-memory database.

SQLite a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications. SQLite file format is stable, cross-platform, and backwards compatible.


PHP 7.0.15, Apache 2.4, Codeigniter 3.1.10

Configuring Codeigniter and SQLite3

Config – database.php

Open file <project root directory>/application/config/database.php file and update the database and dbdriver keys:

'database' => APPPATH.'db/roytuts.sqlite',
'dbdriver' => 'sqlite3',

In the above configurations, database key finds the SQLite3 database file. SQLite3 is the in-memory database, so it’s a database file, for example, roytuts.sqlite and kept under <project root directory>/application/db directory.

If your database file does not exists under the desired folder then the database file will be created with 0 KB.

The dbdriver key finds the database driver. We have given here sqlite3. You don’t need to provide this driver into the Codeigniter framework. The SQLite3 drives comes with the Codeigniter package. You will find sqlite3 driver under <project root directory>/system/database/drivers.

Config – autoload.php

Generally we auto-load things, which are required
to uniformly work throughout the application instead of loading again and again.

Therefore, we will auto-load our database so that it could be loaded once and used throughout the application.

$autoload['libraries'] = array('database');

The above configuration will load database during application startup and if there is any error while loading it will show you.

Testing the Database Connection

Let’s say the file roytuts.sqlite does not exist under
<project root directory>/application/db and when you access the application into browser by hitting URL http://localhost/<project root directory>/index.php, then roytuts.sqlite file will be created with 0 KB in size. If the file already exists then it will be loaded.

If you do not get any error on the browser, it means you have successfully configured Codeigniter 3.1 and SQLite3 in Windows environment.

Thanks for reading.


1 thought on “Configure Codeigniter 3.1 and SQLite3 in Windows

Leave a Reply

Your email address will not be published. Required fields are marked *