如何将 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.
相关文章