如何在Kohana 3中配置SQLite?

问题描述 投票:4回答:3

我正在努力寻找有关如何在Kohana 3.2中配置SQLite的任何信息。我主要需要知道:

  • 我应该将主机名,数据库,用户名和密码设置为什么(使用默认用户且没有密码)?

  • 此外,如何设置SQLite数据库文件的路径?

  • “类型”应该是什么?我尝试使用“ sqlite”,但收到错误Class 'Database_Sqlite' not found

这是我当前的配置选项:

'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,
),
sql sqlite configuration kohana kohana-3
3个回答
5
投票

您可以通过数据库模块使用PDO。正确的配置方式如下所示:

'exportedDatabase' => array(
    'type'       => 'pdo',
    'connection' => array(
        'dsn'        => 'sqlite:/path/to/file.sqlite',
        'persistent' => FALSE,
    ),
    'table_prefix' => '',
    'charset'      => NULL, /* IMPORTANT- charset 'utf8' breaks sqlite(?) */ 
    'caching'      => FALSE,
    'profiling'    => TRUE,
),

在Kohana中使用PDO的一个缺点是,在ORM中,由于不同的数据库系统处理表字段列表的方式,您必须手动指定模型中的所有字段(出于性能原因,您还是应该这样做)。>

还有Banditron创建的real database模块。您必须记住,这不是数据库模块的直接替代,因此Kohana的ORM将not

与它一起使用。除此之外,它非常简洁,对SQLite以外的数据库系统具有广泛的支持。

3
投票

正如我发现的那样,Kohana 3.x实际上并不支持SQLite。有一个不受支持的模块,据我所知,它不起作用。


-1
投票

我不使用Kohana,但这应该可行:

© www.soinside.com 2019 - 2024. All rights reserved.