Question

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,
    ),
Was it helpful?

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);
?>

OTHER TIPS

I dont know kohana, but cant you just simply include file? http://php.net/manual/en/function.include.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top