本文介绍了如何将 CakePHP 连接到 SQLite 数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当基本的问题:我似乎无法将 CakePHP 连接到我的 SQLite 数据库.令人惊讶的是,我没有在互联网上找到很多关于它的信息,尽管我可能查找了错误的关键字.不过,这是我的连接代码:

I have a rather basic problem: I can't seem to connect CakePHP to my SQLite database. Surprisingly, I didn't find lots of information about it on the internet, though I may be looking up the wrong keywords. Nevertheless, this is my connection code:

var $default = array(
        'driver' => 'sqlite',
        'connect' =>'sqlite_popen',
        'persistent' => false,
        'host' => 'localhost',
        'port' => '',
        'login' => '',
        'password' => '',
        'database' => '/home/MY_USER_NAME/public_html/my_database.sqlite',
        'schema' => '',
        'prefix' => '',
        'encoding' => ''
);

不过,Cake 只说Cake 无法连接到数据库".另外,我不知道在哪里可以看到真实"日志(即从 SQLite驱动程序"返回的错误).所以,我遇到了死胡同.我该怎么办?

Still, Cake only says "Cake is NOT able to connect to the database". Also, I don't know where to see the "real" logs (i.e., the error returned from the SQLite "driver"). So, I hit a dead-end. What should I do?

提前致谢.

推荐答案

截至 CakePHP 2.0,开箱即用地支持Sqlite 3.

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

确保在您的 PHP 配置中启用了 sqlite:

Be sure that sqlite is enabled in your PHP configuration:

phpinfo();

app/Config/databases.php里面你可以这样定义Sqlite数据库:

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',
);

现在检查您的 app/webroot/my_database_name.sqlite 文件.

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

这篇关于如何将 CakePHP 连接到 SQLite 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:41