1

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,
    ),
Chris Baker
  • 49,926
  • 12
  • 96
  • 115
Serhiy
  • 2,505
  • 3
  • 33
  • 49

2 Answers2

3

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);
?>
Thierry R.
  • 138
  • 1
  • 1
  • 6
0

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

Chris Baker
  • 49,926
  • 12
  • 96
  • 115
Aurimas Ličkus
  • 9,886
  • 4
  • 24
  • 26
  • The only issue is that Kohana configs return an array... Hope you don't mind but edited your question to show what I mean... Also love the icon... – Serhiy Nov 01 '11 at 17:53
  • Hmm... didn't know edits had to be peer reviewed... maybe I should have put that edit in my original question? – Serhiy Nov 01 '11 at 17:57