DROP TABLE IF EXISTS `sosi`.`sosi`;
CREATE TABLE `sosi`.`sosi` (
`idx` int(10) unsigned NOT NULL AUTO_INCREMENT,
`sosiname` varchar(45) NOT NULL,
`height` int(10) unsigned NOT NULL,
`blood` varchar(45) NOT NULL,
PRIMARY KEY (`idx`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
INSERT INTO `sosi` (`idx`,`sosiname`,`height`,`blood`) VALUES
(1,'윤아',166,'B'),
(2,'수영',170,'O'),
(3,'효연',160,'AB'),
(4,'유리',167,'AB'),
(5,'태연',162,'O'),
(6,'제시카',163,'B'),
(7,'티파니',162,'O'),
(8,'써니',158,'B'),
(9,'서현',168,'A');
②. Flex Project 'ZendAmfTest'를 만듭니다. 머드초보님은 Application server type을 php으로 하셨는데 저는 서버가 외부에 있어서 None/Other로 하였습니다. 로컬이라면 php를 선택하신 다음에 아파치나 iis가 돌아가는 폴더를 지정하면 됩니다. 지정하게 되면 SWF가 서버로 바로 위치하게 되므로 테스트하기 편합니다.
③. 그런 다음 system>application>libraries에 sosimember.php라는 파일을 만듭니다. CI특성상 파일명은 소문자로 만드셔야합니다.
④. 다음은 DB에서 데이터를 가져오고 반환하는 모델을 만듭니다. system>application>models에 sosimodel.php를 생성하시고 아래 코드입력합니다.
-한마디로 말해서 서버와 SWF(플래시)의 통신이 AMF라고 불리는 Binary형식의 프로토콜을 사용하여 이루어지며 서버상에 있는 원격지 객체를 호출합니다.
-가장 작은 패킷 크기에 데이터 통신에 필요한 거의 모든 옵션을 넣을 수 있는 바이너리 메세징 프로토콜
-HTTP(80포트), HTTPS(443)를 통해 통신하기 때문에 방화벽을 무시할 수 있습니다.
-AMF는 플래시 플레이어가 인식 가능한 기본 메세징 포맷이므로 클라이언트에서 데이터 직렬화와 역직렬화가 자동으로 처리되며 속도도 빠릅니다.
-게이트웨이는 HTTP(80포트), HTTPS(443)를 통해 AMF패킷 송수신, AMF직렬화/역직렬화, 적절한 서비스에 요청위임 등을 수행할 수 있는 게이트웨이 라이브러리가 필요합니다. 이러한 게이트웨이 라이브러리 여러 종류 중에 우리는 여기서 ZendAMF라는 것을 사용할 것입니다.
libmcrypt가 정상적으로 설치되지 않은 것이다. libmcrypt.tar.gz 파일을 다운 받아 ./configure && make && make install로 설치
컴파일 시 configure: error: xml2-config not found. Please check your libxml2 installation. 오류가 나오면
yum install *-devel 이것도 안되면 아래와 같이 수행
libxml2 설치 - XML C 파서(Parser)
다운로드 : ftp://xmlsoft.org/libxml2/
[root@localhost apm]# tar xvfz libxml2-2.6.16.tar.gz
[root@localhost apm]# cd libxml2-2.6.16
[root@localhost libxml2-2.6.16]# ./configure && make && make install
[root@localhost libxml2-2.6.16]# cd ..
[root@kimsr php-5.2.7]# make && make install
4.1 PHP 환경설정 파일 복사
[root@kimsr php-5.2.7]# cp php.ini-dist /usr/local/server/apache/conf/php.ini
본인도 APM을 설치하기위해 무단한 노력을 한거 같다. 몇번의 실패와 역경을 딛고 설치에 성고하였다.
모두 오류없이 설치할 수 있기를 기원하며 설치방법을 만들어 보았다.
이 내용은 어디까지나 설치까지만의 내용을 정리한 것이면 설치 완료 후 세팅해야 하는 사항들이 있다
mysql 기본 DB을 설정하거나 Apache httpd.conf 파일등을 수정해야 한다. 이 부분에 대해서는 추후에 올리는 내용에서
/* Detect character encoding with current detect_order */
echo mb_detect_encoding($str);
/* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
echo mb_detect_encoding($str, "auto");
/* Specify encoding_list character encoding by comma separated list */
echo mb_detect_encoding($str, "JIS, eucjp-win, sjis-win");
/* Use array to specify encoding_list */
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
echo mb_detect_encoding($str, $ary);
하지만 한글에 대해선 완벽하게 지원해주지 않는 걸 확인했다. URL의 파라미터에 직접 한글을 입력하여 한 결과 처음 자음이 ㅈ~ㅎ으로 시작하면 UTF-8로 인식한다.
따라 함수를 따로 만들거나 해야 함.
1. detect_encoding함수
Another light way to detect character encoding:
function detect_encoding($string) {
static $list = array('utf-8', 'windows-1251');
foreach ($list as $item) {
$sample = iconv($item, $item, $string);
if (md5($sample) == md5($string))
return $item;
}
return null;
}
2. Function to detect UTF-8, when mb_detect_encoding is not available it may be useful.
Function to detect UTF-8, when mb_detect_encoding is not available it may be useful.
function is_utf8($str) {
$c=0; $b=0;
$bits=0;
$len=strlen($str);
for($i=0; $i<$len; $i++){
$c=ord($str[$i]);
if($c > 128){
if(($c >= 254)) return false;
elseif($c >= 252) $bits=6;
elseif($c >= 248) $bits=5;
elseif($c >= 240) $bits=4;
elseif($c >= 224) $bits=3;
elseif($c >= 192) $bits=2;
else return false;
if(($i+$bits) > $len) return false;
while($bits > 1){
$i++;
$b=ord($str[$i]);
if($b < 128 || $b > 191) return false;
$bits--;
}
}
}
return true;
}
3. conver to Utf8 if $str is not equals to 'UTF-8'
/*
*QQ: 290359552
* conver to Utf8 if $str is not equals to 'UTF-8'
*/
function convToUtf8($str){
if( mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK")!="UTF-8" ){
return iconv("gbk","utf-8",$str);
}else{
return $str;
}
}
6. Sometimes mb_detect_string is not what you need. When using pdflib for example you want to VERIFY the correctness of utf-8. mb_detect_encoding reports some iso-8859-1 encoded text as utf-8. To verify utf 8 use the following:
//
// utf8 encoding validation developed based on Wikipedia entry at:
// http://en.wikipedia.org/wiki/UTF-8
//
// Implemented as a recursive descent parser based on a simple state machine
// copyright 2005 Maarten Meijer
//
// This cries out for a C-implementation to be included in PHP core
//
function valid_1byte($char) {
if(!is_int($char)) return false;
return ($char & 0x80) == 0x00;
}
function valid_2byte($char) {
if(!is_int($char)) return false;
return ($char & 0xE0) == 0xC0;
}
function valid_3byte($char) {
if(!is_int($char)) return false;
return ($char & 0xF0) == 0xE0;
}
function valid_4byte($char) {
if(!is_int($char)) return false;
return ($char & 0xF8) == 0xF0;
}
function valid_nextbyte($char) {
if(!is_int($char)) return false;
return ($char & 0xC0) == 0x80;
}
function valid_utf8($string) {
$len = strlen($string);
$i = 0;
while( $i < $len ) {
$char = ord(substr($string, $i++, 1));
if(valid_1byte($char)) { // continue
continue;
} else if(valid_2byte($char)) { // check 1 byte
if(!valid_nextbyte(ord(substr($string, $i++, 1))))
return false;
} else if(valid_3byte($char)) { // check 2 bytes
if(!valid_nextbyte(ord(substr($string, $i++, 1))))
return false;
if(!valid_nextbyte(ord(substr($string, $i++, 1))))
return false;
} else if(valid_4byte($char)) { // check 3 bytes
if(!valid_nextbyte(ord(substr($string, $i++, 1))))
return false;
if(!valid_nextbyte(ord(substr($string, $i++, 1))))
return false;
if(!valid_nextbyte(ord(substr($string, $i++, 1))))
return false;
} // goto next char
}
return true; // done
}
for a drawing of the statemachine see: http://www.xs4all.nl/~mjmeijer/unicode.png and http://www.xs4all.nl/~mjmeijer/unicode2.png