1

有没有一种简单的方法可以在非 Kohana 应用程序中使用 Kohana DB 配置文件?通过阅读 Kohana_Config 类,我似乎无法弄清楚。

为什么?假设我有一个位于同一目录中的 cron 任务,我希望它使用相同的数据库配置。

这种愚蠢的尝试以失败告终……

function connection(){
    $connection = file_get_contents('../application/config/database.php');
    eval($connection);
}

以下是配置示例:

return array
(
    'default' => array
    (
            'type'       => 'mysql',
            'connection' => array(
                    'hostname'   => 'localhost',
                    'database'   => 'some_db',
                    'username'   => 'root',
                    'password'   => 'root',
                    'persistent' => FALSE,
            ),
            'table_prefix' => '',
            'charset'      => 'utf8',
            'caching'      => FALSE,
            'profiling'    => TRUE,
    ),
4

2 回答 2

3

我在 kohana 的根目录下创建了一个文件 test.php

<?php
    define('SYSPATH',"foo");

    function foo($file) {
      return include $file;
    }

    $config = array();
    $config = foo("application/config/database.php");

    print_r($config);
?>
于 2011-11-01T18:20:11.490 回答
0

我不知道kohana,但你不能简单地包含文件吗?http://php.net/manual/en/function.include.php

于 2011-11-01T17:47:12.833 回答