function user_func(){
global $config;
//$config 함수를 이용
}
혹은
2. 테이블을 이용하는 방법
#####################
환경설정
####################
$config = sql("select * from config_table");
해당 스키마를 보면,
CREATE TABLE IF NOT EXISTS `config` (
`cf_title` varchar(255) NOT NULL default '',
`cf_admin` varchar(255) NOT NULL default '',
`cf_use_point` tinyint(4) NOT NULL default '0',
`cf_use_norobot` tinyint(4) NOT NULL default '0',
`cf_use_copy_log` tinyint(4) NOT NULL default '0',
`cf_use_email_certify` tinyint(4) NOT NULL default '0',
`cf_login_point` int(11) NOT NULL default '0',
`cf_cut_name` tinyint(4) NOT NULL default '0',
`cf_nick_modify` int(11) NOT NULL default '0',
`cf_new_skin` varchar(255) NOT NULL default '',
`cf_login_skin` varchar(255) NOT NULL default '',
`cf_new_rows` int(11) NOT NULL default '0',
`cf_search_skin` varchar(255) NOT NULL default '',
`cf_10` varchar(255) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
위와 같이 여러가지의 이름을 가지는 필드가 환경 설정의 $confg 배열로 사용하는 방법
혹은 $config = sql("select * from config_table where id = 1");
와 같이 사용하기도 합니다.
3. parse_ini_file 파일을 이용한 방법
설명 생략 ;;;
###############################################
위의 3가지 방법의 공통점은 무엇일까요?
###############################################
1. 다양한 환경변수를 만들수가 없다.
###############################################
2. 환경변수를 늘리려면, 필드를 늘리거나, config 변수를 수정해야 한다.
###############################################
3. 모듈화 할 수 없다
###############################################
저는 위의 3가지 방법의 이러한 단점이 존재한다고 생각하고 있습니다.
##############################################
아래의 방법은 우리나라는 아니지만, 좀 유명한 프레임워크에서 사용하는
환경설정을 이용하는 방식입니다.
//특정한 환결설정 변수를 호출 합니다.
function _get_config($name = false,$module = 'config') {
static $config = null;//$config 는 항상 기억하고 있습니다.
if(!isset($config)) { //$config 가 없다면, 아래의 함수를 실행합니다.
$config = _set_config();
}
if (empty($config[$module][$name])) {
$config[$module][$name] = false;
} // end of if
return $config[$module][$name];
} // end of function
//환경설정 사항을 select 한다,
function _set_config(){
$config = array();
$sql = "SELECT * FROM xxx_config";
$rs = mysql_query($sql);
while ( $row = mysql_fetch_array($rs) ) {
$config[$row['cf_module']][$row['cf_name']] = $row['cf_value'];
}
return $config;
}
//환경설정을 insert 합니다.
function _insert_config($name, $value, $module = 'config') {
$sql = "select count(*) as cnt from xxx_config where cf_name = '$name' and cf_module ='$module'";
$row = sql_fetch($sql);
if ($row[cnt]) {
return false;
}
$QUE = "INSERT INTO xxx_config SET ";
$QUE .= "cf_name = '".trim($name)."',";
$QUE .= "cf_value= '".addslashes(trim($value))."'";
$QUE .= "cf_module= '".trim($hook)."'";
$rs = mysql_query($QUE);
} // end of function
//환경설정을 업데이트 합니다.
function _update_config($name,$value, $module = 'config') {
$sql = "select count(*) as cnt from xxx_config where cf_name = '$name' and cf_module='$module";
$row = sql_fetch($sql);
if ($row[cnt]) {
$value = addslashes(trim($value));
$sql = "update xxx_config set cf_value = '$value' where cf_name = '$name' and cf_module='$module";
$rs = sql_query($sql);
} else {
_insert_config($name,$value,$module);
}
} // end of function