在 CakePHP 中使用 Sqlite3 [英] Using Sqlite3 with CakePHP

查看:24
本文介绍了在 CakePHP 中使用 Sqlite3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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'

这篇关于在 CakePHP 中使用 Sqlite3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆