Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SQLite3 with CakePHP 2.0

I'm trying to run SQLite3 with CakePHP 2.0

In these questions I saw that it's possible to do that in CakePHP 1.3:
- Using Sqlite3 with CakePHP
- How do I connect CakePHP to a SQLite database?

However, the solutions are not valid for CakePHP 2.0.

I configured the file 'database.php' and I got success on the starting page of CakePHP. It was able to connect to the database (but I do not know where to find the .db3 database file).

I used the following code:

public $default = array(
    'datasource' => 'Database/Sqlite',
    'persistent' => false,
    'host' => 'localhost',
    'login' => '',
    'password' => '',
    'database' => 'cake_blog_tutorial',
    'prefix' => '',
    //'encoding' => 'utf8',
);

I'm trying to find out:

  1. Where should my cake_blog_tutorial.db3 file be kept
  2. Is the datasource different for SQLite3, for example 'Database/Sqlite3'?

Thank you for your help!

like image 485
Paulo Coghi Avatar asked Nov 07 '11 10:11

Paulo Coghi


1 Answers

In short, the answer is that Sqlite3 databases in CakePHP 2.0 take something like the following configuration:

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

The sqlite file is then automatically created in the webroot directory (unless you prepend a relative path to the database name).

Incidentally, you can use in-memory Sqlite databases (for testing purposes, for example) by changing the database name to ":memory:", e.g.:

public $default = array(
        'datasource' => 'Database/Sqlite',
        'persistent' => false,
        'database' => ':memory:',
        'prefix' => '',
        //'encoding' => 'utf8',
);
like image 96
Jon Cairns Avatar answered Nov 16 '22 03:11

Jon Cairns