如何在 Kohana 3 中配置 SQLite?
我正在努力寻找有关如何在 Kohana 3.2 中配置 SQLite 的任何信息。我主要需要知道:
我应该设置什么主机名、数据库、用户名和密码(使用默认用户且无密码)?
另外,如何设置SQLite数据库文件的路径?
“类型”应该是什么?我尝试了“sqlite”,但收到错误
未找到“Database_Sqlite”类
。
这是我当前的配置选项:
'exportedDatabase' => array
(
'type' => 'sqlite',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => $hostname,
'database' => $database,
'username' => $username,
'password' => $password,
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
I'm struggling to find any information on how to configure SQLite in Kohana 3.2. I mainly need to know:
What should I set hostname, database, username and password to (with default user and no password)?
Also, how can I set the path to the SQLite database file?
What should the "type" be? I tried "sqlite" but I get an error
Class 'Database_Sqlite' not found
.
This is my current configuration options:
'exportedDatabase' => array
(
'type' => 'sqlite',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => $hostname,
'database' => $database,
'username' => $username,
'password' => $password,
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过数据库模块使用PDO。正确的配置方法如下所示:
在 Kohana 中使用 PDO 的一个缺点是,在 ORM 中,您必须在模型中手动指定所有字段(出于性能原因,无论如何都应该这样做),因为不同的数据库系统处理列表的方式不同表字段。
还有 Banditron 创建的 真实数据库 模块。您必须记住,它不是数据库模块的直接替代品,因此 Kohana 的 ORM 将无法使用它。除此之外,它非常简洁,并且对 SQLite 以外的数据库系统有广泛的支持。
You can use PDO through Database module. The proper way of configuring it looks like this:
One disadvantage of using PDO in Kohana is that in ORM you have to specify all fields by hand in your model (you should do it anyway for performance reasons) because of how different database systems handle listing of table fields.
There is also real database module created by banditron. You have to remember that's it is NOT a drop-in replacement for Database module and therefore Kohana's ORM will not work with it. Other than that it's pretty neat and has wide support for database systems other than SQLite.
据我发现,Kohana 3.x 实际上并不支持 SQLite。它有一个不受支持的模块,据我所知,它不起作用。
使用 PDO 非常简单,而且语法与 Kohana 的 ORM 几乎相同:
As I found out, Kohana 3.x doesn't actually support SQLite. There's an unsupported module for it and, as far as I can tell, it's not working.
It's easy enough to use PDO though and the syntax is pretty much the same as Kohana's ORM:
我不使用 Kohana,但这应该有效:
I don't use Kohana, but this should work: