FuelPHP无法设置数据库工作

时间:2014-04-18 13:50:06

标签: php database fuelphp

我使用的是FuelPHP,但我无法设置数据库,因此可以使用。我知道我使用了正确的信息,但我不确定我是否把它放在正确的位置。

<?php

return array(
'default' => array(
    'connection'  => array(
        'dsn'        => 'mysql:host=modernt@moderntalking.lt;dbname=modernt',
        'username'   => 'modernt',
        'password'   => 'pass',
    ),
),
);

这是我在APP / config / db.php中的db.php

4 个答案:

答案 0 :(得分:2)

合并环境配置,环境获胜。

因此,如果您的./app/config/db.php包含return array('a');并且您的./app/config/development/db.php包含return array('b');,那么在阅读之后你的配置,你最终会得到&#34; b&#34;。

因此,如果您使用基于环境的配置(默认情况下与DB一样),则只将配置添加到真正全局的全局文件中,否则它将在合并中被覆盖。

答案 1 :(得分:0)

检查

'dsn' => 'mysql:host=moderntalking.lt;dbname=modernt',

答案 2 :(得分:0)

// a MySQL driver configuration
'development' => array(
    'type'           => 'mysqli',
    'connection'     => array(
        'hostname'       => 'localhost',
        'port'           => '3306',
        'database'       => 'fuel_db',
        'username'       => 'your_username',
        'password'       => 'y0uR_p@ssW0rd',
        'persistent'     => false,
        'compress'       => false,
    ),
    'identifier'     => '`',
    'table_prefix'   => '',
    'charset'        => 'utf8',
    'enable_cache'   => true,
    'profiling'      => false,
    'readonly'       => false,
),

// a PDO driver configuration, using PostgreSQL
'production' => array(
    'type'           => 'pdo',
    'connection'     => array(
        'dsn'            => 'pgsql:host=localhost;dbname=fuel_db',
        'username'       => 'your_username',
        'password'       => 'y0uR_p@ssW0rd',
        'persistent'     => false,
        'compress'       => false,
    ),
    'identifier'     => '"',
    'table_prefix'   => '',
    'charset'        => 'utf8',
    'enable_cache'   => true,
    'profiling'      => false,
    'readonly'       => array('slave1', 'slave2', 'slave3'),
),

'slave1' => array(
    // configuration of the first production readonly slave db
),

'slave2' => array(
    // configuration of the second production readonly slave db
),

'slave3' => array(
    // configuration of the third production readonly slave db
),

设置FuelPHP的基本程序。可以帮助你。谢谢你

答案 3 :(得分:0)

首先,检查app/bootstrap.php中的环境配置:

/**
* Your environment. Can be set to any of the following:
*
* Fuel::DEVELOPMENT
* Fuel::TEST
* Fuel::STAGING
* Fuel::PRODUCTION
*/
Fuel::$env = (isset($_SERVER['FUEL_ENV']) ? $_SERVER['FUEL_ENV'] : Fuel::DEVELOPMENT);

然后相应地修改db.php文件(app/development/db.php, app/production/db.php, app/staging/db.php, app/test/db.php