CI 묻고 답하기

제목 tank_auth 스키마 질문.
글쓴이 emc 작성시각 2009/08/21 11:32:27
댓글 : 5 추천 : 0 스크랩 : 0 조회수 : 29400   RSS
금궁해서 질문 드립니다.
보통 테이블 생성할때 collate utf8_bin 옵션을 사용하지 않고 생성했는데요.
tank_auth 보니까 거의 해당 옵션이 설정되어 테이블을 생성하고 있습니다.
옵션을 주고 생성하면 어떤 점이 다른지 궁금합니다.

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL auto_increment,
  `role_id` int(11) NOT NULL default '1',
  `username` varchar(25) collate utf8_bin NOT NULL,
  `password` varchar(34) collate utf8_bin NOT NULL,
  `email` varchar(100) collate utf8_bin NOT NULL,
  `banned` tinyint(1) NOT NULL default '0',
  `ban_reason` varchar(255) collate utf8_bin default NULL,
  `newpass` varchar(34) collate utf8_bin default NULL,
  `newpass_key` varchar(32) collate utf8_bin default NULL,
  `newpass_time` datetime default NULL,
  `last_ip` varchar(40) collate utf8_bin NOT NULL,
  `last_login` datetime NOT NULL default '0000-00-00 00:00:00',
  `created` datetime NOT NULL default '0000-00-00 00:00:00',
  `modified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=3 ;


 다음글 프레임 워크 사용시 코드가 꼬이는게 고민입니다. MVC... (8)
 이전글 CI VIew (4)

댓글

양승현 / 2009/08/21 12:38:32 / 추천 0
잘은 모르겠으나 collate는 디폴트 콜렉션을 무시하려고 할때 사용한다고 하네요.
제 생각에는 테이블의 콜렉션이 euc-kr일때 해당 칼럼만 utf-8로 지정하고자 할때 사용할수 있겠네요.
디비 > 테이블 > 칼럼 요로케 종속되잖아요? 각각을 지정해주면 각각 따로 사용할수 있는?

확실한건 아니지만 디폴트 콜렉션을 무시하는건 메뉴얼에 나와있어요 ^^;
변종원(웅파) / 2009/08/21 12:38:38 / 추천 0
저도 질문하신거 구글에서 검색해보고 알았네요. 그냥 습관적으로 utf8_general_ci 로 사용을 했었는데...

NogDog
08-18-2007, 07:57 AM
utf8_bin: compare strings by the binary value of each character in the string

utf8_general_ci: compare strings using general language rules and using case-insensitive comparisons

utf8_general_cs: compare strings using general language rules and using case-sensitive comparisons

For example, the following will evaluate at true with either of the UTF8_general collations, but not with the utf8_bin collation:

Ä = A
Ö = O
Ü = U

With the utf8_general_ci collation, they would also return true even if not the same case.

None of these is inherently "better"; they simply have different functionalities. You need to choose which one best suits your particular needs.

deezerd
08-18-2007, 08:10 AM
thanks for your very clear answer :)

which makes me think to another question:

what are the consequences if utf8_bin collation doesn't evaluate at true Ä = A

I mean, will it change the way my php script work if I use some sort or str_replace functions?
For example, does it mean these two tests below will return the same result?

$string = 'Ä'; // result that would come from my table

str_replace("Ä","foo",$string);

str_replace("A","foo",$string);

thanks


결론은 utf8_general 에서는 Ä = A  이 맞다고 나오고 utf8_bin 에서는 틀리게 체크한다 입니다.
국내만 사용한다면 문제가 안되겠지만 위와 같은 문자를 사용하여 아이디를 쓰게 한다면 utf8_bin 으로
셋팅하는 것이 맞겠네요.
양승현 / 2009/08/21 13:07:40 / 추천 0
어렵다.. ㅜ.ㅜ;; 영어
emc / 2009/08/21 13:26:13 / 추천 0
그렇군요. 공부가 되었습니다. 감사합니다. ^^;
듬직이 / 2009/08/21 13:58:19 / 추천 0
아.. 그런 차이가 있었군요.. 좋은 정보 감사드립니다.