在 CakePHP 中使用 Sqlite3

2021-12-21 00:00:00 configuration cakephp sqlite

我正在尝试使用 CakePHP 运行 Sqlite3.是的,我知道它没有得到官方支持,但是这篇文章在这里:如何将 CakePHP 连接到 SQLite 数据库?说有可能.我已经下载了新的驱动程序文件dbo_sqlite3.7.php"并将其放在cake/libs/model/datasources/dbo"中.现在我无法连接到数据库.

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.

让我感到困惑的事情:

  1. 我的database.sqlite文件应该保存在哪里

  1. Where should my database.sqlite file be kept

我的配置文件应该是什么样的.我应该引用驱动程序的完整文件名吗?像'驱动程序' => 'dbo_sqlite3.7.php'?我可以使用 db 文件的相对路径吗?

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?

sqlite3 文件和 sqlite2 文件本身是否有区别,还是只是您处理文件的方式不同?

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.

推荐答案

驱动文件应该命名为 dbo_sqlite3.php.您可以从 GitHub 下载最新版本.

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 将在 app/webroot 中查找数据库文件.您可以使用绝对路径或相对于 webroot 目录的路径.例如,如果您更愿意将数据库存储在应用程序目录中(从 webroot 上一层),您可以这样写:

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'

相关文章