如何将CakePHP连接到SQLite数据库? [英] How do I connect CakePHP to a SQLite database?

查看:111
本文介绍了如何将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 文件。

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

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