Using Sqlite3 with CakePHP

2019-02-11 02:49发布

I'm trying to run Sqlite3 with CakePHP. Yes, i know it's not officially supported, but this post here: How do I connect CakePHP to a SQLite database? says it's possible. I've downloaded the new driver file "dbo_sqlite3.7.php" and put it in "cake/libs/model/datasources/dbo". Now I'm having trouble getting connected to the db.

Things I'm confused on:

  1. Where should my database.sqlite file be kept

  2. What should my config file look like. Should I be referencing the full filename of the driver? Like 'driver' => 'dbo_sqlite3.7.php'? And can I use relative paths to the db file?

  3. Is there a difference in sqlite3 files and sqlite2 files by themselves, or is it just the way that you handle the files that makes the difference?

Thank you for your help. I'm new to cake and I'm excited about learning more.

1条回答
Juvenile、少年°
2楼-- · 2019-02-11 03:32

The driver file should be named dbo_sqlite3.php. You can download the latest version from GitHub.

Your database config could look like this:

var $default = array(
    'driver' => 'sqlite3',
    'database' => 'database.sqlite'
);

CakePHP will look for the database file in app/webroot. You can use an absolute path or a path relative to the webroot directory. For example, if you'd rather store the database in the app directory (one level up from the webroot), you could write:

'database' => '../database.sqlite'
查看更多
登录 后发表回答