How do I connect CakePHP to a SQLite database?

How to CakePHP with SQLite3:

Requirments:

  • CakePHP version 1.3
  • Datasources plugin

Steps:

Unpack the Datasources plugin in place.

Edit dbo_sqlite3.php and add:

App::import('Datasource','DboSource');

...just before the 'class' definition.

Use the following configuration in your database.php file:

var $default = array(
    'datasource' => 'Datasources.DboSqlite3',
    'login' => '',
    'password' => '',
    'database' => '/full/path/to/db.sqlite');

Done.


As of CakePHP 2.0, Sqlite 3 is supported out of the box.

Be sure that sqlite is enabled in your PHP configuration:

phpinfo();

Inside app/Config/databases.php you can define Sqlite database like this:

public $default = array(
        'datasource' => 'Database/Sqlite',
        'persistent' => false,
        'database' => 'my_database_name',
        'prefix' => '',
        'encoding' => 'utf8',
);

Now check your app/webroot/my_database_name.sqlite file.


SQLite3 is not officially supported yet by CakePHP... probably because the file attached to this bug/enhancement works.

https://trac.cakephp.org/ticket/3003

Grab the latest version of the file, update it with any newer patches, upload it to your cake/libs/model/datasources/dbo directory and configure it in your database.php file.

I am using a file called dbo_sqlite3.php

My configuration file uses this for the driver setting:

  'driver' => 'sqlite3',

Tags:

Sqlite

Cakephp