class_mcConfig.inc.php
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?
class mcConfig {
private static $configs = array (
'tmpdir' => '/tmp/',
'charset' => 'utf-8',
'storable_data' => array(
'kindof' => 'MySql',
'user' => 'user',
'db' => 'database',
'passwd' => 'password',
'host' => 'localhost',
),
);
public static function setConfig(array $param_Configs) {
if(is_array($param_Configs) && !empty($param_Configs)) {
self::$configs = $param_Configs;
return true;
} else {
return false;
}
}
public static function getConfig($param_column, $param_param=null) {
if(array_key_exists($param_column, self::$configs)) {
if(is_null($param_param)) {
return self::$configs[$param_column];
} else if(array_key_exists($param_param, self::$configs[$param_column])) {
return self::$configs[$param_column][$param_param];
} else {
return false;
}
} else {
return false;
}
}
public static function getDSN() {
if(array_key_exists('storable_data', self::$configs) && is_array(self::$configs['storable_data'])
&& array_key_exists('kindof', self::$configs['storable_data']) && self::$configs['storable_data']['kindof']
&& array_key_exists('user', self::$configs['storable_data']) && self::$configs['storable_data']['user']
&& array_key_exists('db', self::$configs['storable_data']) && self::$configs['storable_data']['db']
&& array_key_exists('passwd', self::$configs['storable_data']) && self::$configs['storable_data']['passwd']
&& array_key_exists('host', self::$configs['storable_data']) && self::$configs['storable_data']['host']
) {
$dsn= strtolower(self::$configs['storable_data']['kindof'])
.'://'.self::$configs['storable_data']['user']
.':'.self::$configs['storable_data']['passwd']
.'@'.self::$configs['storable_data']['host']
.'/'.self::$configs['storable_data']['db'];
D::li($dsn);
return $dsn;
} else {
return false;
}
}
}
?>