MySQL SET type field 처리를 좀 더 쉽게? > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

MySQL SET type field 처리를 좀 더 쉽게? 정보

MySQL SET type field 처리를 좀 더 쉽게?

본문

그누보드의 경우 au_auth ('r', 'w', 'd'), wr_option('html1','html2','secret','mail') 두 개 필드가 해당됩니다.
입출력 소스에서 약간의 문제점이 있는 듯 하며, 간혹 오류가 나는 경우도 있습니다.
- MySQL 홈페이지에도 이 문제가 보고되었습니다. set type 메뉴얼 (제일 아래) 참고.
- 그누보드 소스의 경우 ",,"와 같은 문제 외에도,
- DB에 저장된 내용을 불러와 참조할 때, 예를 들어 checkbox에서 "checked" 이용할 때...
- 소스가 좀 복잡한 듯 하여 다음과 같이 제안합니다.

[sql 쿼리: ]
wr_option의 경우 1=html, 2=autobr, 4=secret, 8=mail 이며, (1,2)는 모두 HTML이고 자동줄바꿈 처리 유무로 구분되므로 동시에 적용되지 않습니다. 즉,
wr_option 이 가질 수 있는 경우를 10진수로 구해보면;
0과 (1,4,8의 조합)에서 1,4,5,8,9,12,13, (2,4,8의 조합)에서 2,4,6,8,10,12,14 이므로
0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14 모두 12 경우가 나옵니다.

[순서를 바꾸면, wr_option ('secret', 'mail', 'autobr', 'html')의 경우
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11이 나오겠죠 (좀더 인간적이죠^^)]

checkbox에서 선택 여부에 따라 각각 ''과 1의 값을 갖도록 하여 폼으로 넘기면,
<tinput type='checkbox' name='secret' value=1 <?if($secret)?'checked':'';?>>
<tinput type='checkbox' name='maili'  value=2 <?if($mail)?  'checked':'';?>>
<tinput type='checkbox' name='autobr' value=4 <?if($autobr)?'checked':'';?>>
<tinput type='checkbox' name='html' value=8 <?if($html)?'checked':'';?>>

다음과 같이 쿼리문에 바로 사용할 수 있습니다.
insert into (update) TABLE set ..., wr_option=$secret+$mail+$autobr+$html, ...


[PHP에서:]
인클루드 하여 사용되는 LIB에서 쿼리문 작성시 다음과 같이 권한변수들을 직접 받습니다.

mysql> select *, substring(bin(au_auth+8),4,1) as reading, substring(bin(au_auth+8),3,1)*2 as writing, substring(bin(au_auth+8),2,1)*4 as deleting from g4_auth;
+---------+--------------+-------------+-----------+----------+-------------+
| mb_id | au_menu | au_auth | reading | writing | deleting |
+---------+--------------+-------------+-----------+----------+-------------+
|          |              |    r,d    |    1      |    0    |    4        |
+---------+--------------+-------------+-----------+----------+-------------+

mysql> select wr_id, wr_option, substring(bin(wr_option+16),2,1)*8 as mail, substring(bin(wr_option+16),3,1)*4 as secret, substring(bin(wr_option+16),4,1)*2 as html2, substring(bin(wr_option+16),5,1) as html1 from g4_write_apmsetup;
+---------+---------------+------+----------+---------+---------+
| wr_id | wr_option | mail | secret | html2 | html1 |
+---------+---------------+------+----------+---------+---------+
|    1    |    html2    |    0    |    0      |    2    |    0    |
+---------+---------------+------+----------+---------+---------+
$write[html2], $html2과 같이 바로 적용할 수 있습니다.

* 참고 :
1) au_auth+8, wr_option+16 ?
2진수로 변환하면 값 유무를 알 수 있다. 예)(r,d) 101, (w,d) 11
(w,d)가 011이 아닌 11로 나타나므로 substring오류를 피하기 위한 트릭.
2) 소스를 정리하는 것은 다음 기회로 미루고, wr_option 관련 파일들은 다음과 같습니다.
[au_auth]
----------------------------------------------------------------------------------------------
adm/auth_list.php
adm/auth_update.php
adm/admin.lib.php
----------------------------------------------------------------------------------------------
[wr_option]
----------------------------------------------------------------------------------------------
bbs\move_update.php
bbs\write.php
skin\board\write.skin.php
bbs\write_update.php
bbs\view.php"
lib\common.lib.php
이외 몇개 더 있을 것 같네요.

스크렙/코멘트의 경우는 상관 없나보네요. 혹시나...
bbs\scrap_popin_update.php
bbs\write_comment_update.php
----------------------------------------------------------------------------------------------
추천
0

댓글 0개

전체 3,309 |RSS
그누4 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT