Search code examples
phpkohanakohana-3kohana-3.2

Using a Kohana Config in a non Kohana app


Is there an easy way to use a Kohana DB config file in a non Kohana app? I can't seem to figure it out by reading through the Kohana_Config class.

Why? Say I have a cron task that sits in the same directory and I'd like it to use the same DB config.

This silly attempt ended at a fail...

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

Here is a sample of the config:

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,
    ),

Solution

  • I created a file test.php in the root of kohana

    <?php
        define('SYSPATH',"foo");
    
        function foo($file) {
          return include $file;
        }
    
        $config = array();
        $config = foo("application/config/database.php");
    
        print_r($config);
    ?>