본문 바로가기
정보기술/일반

MySQL 4.x 에서 5.x 로 변경시 한글(UTF-8) 및 Password 문제

by fermi 2007. 8. 27.
한글 문제

MySQL DB 연결시, 기본 언어 설정이 UTF-8일때, 제로보드에서 euckr을 사용하기 때문에 발생하는 문제로 이다.

따라서 @mysql_connect() 함수가 나올때마다 mysql_query("SET NAMES euckr"); 와 같이 언어 설정을 해줌으로 해결이 가능함.

mysql_connect()함수를 검색해 보면 다음 3개의 문서에서 발견할 수 있다.
--------------------------
install_ok.php
lib.php
admin_uninstall.php
--------------------------

예를 들어 lib.php의 dbconn()함수를 다음과 같이 수정
--------------------------------------------------------------------------------------------------------

        function dbconn() {

                global $connect, $config_dir, $autologin, $HTTP_COOKIE_VARS, $_dbconn_is_included;

                if($_dbconn_is_included) return;
                $_dbconn_is_included = true;

                $f=@file($config_dir."config.php") or Error("config.php파일이 없습니다.
DB설정을 먼저 하십시요","install.php");

                for($i=1;$i<=4;$i++) $f[$i]=trim(str_replace("\n","",$f[$i]));

                if(!$connect) $connect = @mysql_connect($f[1],$f[2],$f[3]) or Error("DB 접속시 에러가 발생했습니다");

                // MySQL 5.0.45 설치후 utf-8 의 한글 문제로 한글이 제로보드에서 ?(물음표)로 표현되는 문제 해결 - fermi (2007.08.26)
                if($connect) mysql_query("SET NAMES euckr");
                // 수정 끝

                @mysql_select_db($f[4], $connect) or Error("DB Select 에러가 발생했습니다","");
        
                return $connect;
        }
--------------------------------------------------------------------------------------------------------


Password 문제

Password 문제는 MySQL의 4.x 의 password()함수와 5.x의 password()함수의 차이로 발생하는 문제로 5.x에서는 이를 위하여 old_password()함수를 제공하고 있다.

따라서 php의 mysql_query()함수 내에 들어있는 password()함수를 모두 old_password()로 변경한다.

예를 들면
$temp=mysql_fetch_array(mysql_query("select password('$password')"));
를 다음과 같이 수정한다. (모든 함수에 대하여 replace)
$temp=mysql_fetch_array(mysql_query("select old_password('$password')"));