본문으로 바로가기

CodeIgniter 02.환경설정 및 DB연결

category 프로그래밍/PHP 2019. 3. 27. 14:23
반응형

 

-- 개인 작업 환경 및 개발을 하기 위해 필요한 부분만 정리한 내용입니다.

-- 자세한 내용 및 정보는 CodeIgniter 메뉴얼 및 CodeIgniter 한국 사용자 포럼을 이용해 주세요.

 

 

1. 기본 환경 설정.

 

- 파일명 : application/config/config.php

- 설정할 항목들.

 

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of 'REQUEST_URI' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
|
| WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
*/
$config['uri_protocol'] = 'REQUEST_URI';

 

- uri_protocol : REQUEST_URI

 

/*
|--------------------------------------------------------------------------
| Default Language
|--------------------------------------------------------------------------
|
| This determines which set of language files should be used. Make sure
| there is an available translation if you intend to use something other
| than english.
|
*/
$config['language'] = 'english';

 

- 기본 Language 설정 : english

 

/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
*/
$config['charset'] = 'UTF-8';

 

- 기본 문자 셋 정의 : default UTF-8

 

/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
|   0 = Disables logging, Error logging TURNED OFF
|   1 = Error Messages (including PHP errors)
|   2 = Debug Messages
|   3 = Informational Messages
|   4 = All Messages
|
| You can also pass an array with threshold levels to show individual error types
|
|   array(2) = Debug Messages, without Error Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 4;

 

- 개발을 위해 4 = All Message 로 설정.

 

 

2. DB 연결 설정.

 

- 위치 : application/config/database.php

 

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'devuser',
    'password' => 'devpasswd',
    'database' => 'devdb',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

 

- Database 연결을 위해  username, password, database 명을 추가해 준다/

 

- mysql db 생성 및 유저 생성 사용법

 

create database [디비명] default character set [문자셋];
 
create user '계정'@'%' identified by '패스워드';
grant all on 디비명.* to '계정'@'*';
or
create user '계정'@'localhost' identified by '패스워드';
grant all on 디비명.* to '계정'@'localhost';
 
flush privileges;

 

- 예시.

create database devdb default character set utf8;
 
create user 'devuser'@'%' identified by 'devpassword';
grant all on devdb.* to 'devuser'@'%';
or
create user 'devuser'@'localhost' identified by 'devpassword';
grant all on devdb.* to 'devuser'@'localhost';
 
flush privileges;

 

 

반응형