[英]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? 有没有一种简单的方法在非Kohana应用程序中使用Kohana数据库配置文件? I can't seem to figure it out by reading through the Kohana_Config class.
通过阅读Kohana_Config课,我似乎无法弄明白。
Why? 为什么? Say I have a cron task that sits in the same directory and I'd like it to use the same DB config.
假设我有一个位于同一目录的cron任务,我希望它使用相同的数据库配置。
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,
),
I created a file test.php in the root of kohana 我在kohana的根目录中创建了一个文件test.php
<?php
define('SYSPATH',"foo");
function foo($file) {
return include $file;
}
$config = array();
$config = foo("application/config/database.php");
print_r($config);
?>
I dont know kohana, but cant you just simply include file? 我不知道kohana,但是您不能只包含文件吗? http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.include.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.