달력

05

« 2018/05 »

  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  

'FreeTDS'에 해당되는 글 1

  1. 2017.05.27 FreeTDS - 리눅스에서 MSSQL 접속하기 - tsql

FreeTDS - 리눅스에서 MSSQL 접속하기 - tsql


FreeTDS - tsql 설치

# wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz (지금은 버전이 0.91 )
# tar -xvzf freetds-stable.tgz
# cd freetds-0.91
# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --disable-odbc --disable-debug --enable-msdblib
# make -j 4  (CPU core 4개를 사용해서 빠르게 컴파일하기)
# make install


MSSQL 서버설정 추가

/usr/local/freetds/etc/freetds.conf  에 추가.

MSSQL 2005 이상이라면 tds version = 8.0
MSSQL 2005 미만이라면 tds version = 7.0

[123.123.123.123]
   host = 123.123.123.123
   port = 1433
   tds version = 8.0
   client Charset = utf8


캐릭셋때문에 한글/일본어/중국어 등이 깨지면 client charset 부분을 아래중에서 하나로 바꿔본다.

문자가 깨질때 아래와 같은 에러가 뜬다.


Error 2403 (severity 4):
        Some character(s) could not be converted into client's character set.  Unconverted bytes were changed to question marks ('?')


#       locale is "ko_KR.UTF-8"
#       locale charset is "UTF-8"
        # Latin1_General_CI_AS, Korean_Wansung_CI_AS
        #client charset = ko_KR.UTF-8
        #client charset = EUC-KR
        client charset = UTF-8
        #client charset = ANSI_X3.4-1968
        #client charset = MS-ANSI
        #client charset = Korean_Wansung_CI_AS
        #client charset = Latin1_General_CI_AS
        #locale charset = UTF-8
        #locale = ko_KR.UTF-8
        #locale charset = UTF-8


MS-SQL 접속 테스트

   # /usr/local/freetds/bin/tsql -H MSSQL서버아이피 -p MSSQL서버포트 -U 디비계정 -P 디비비밀번호

PHP - mssql 모듈 설치

   # cd /usr/local/src/php-5.2.9/ext/mssql
   # /usr/local/php/bin/phpize
   # ./configure --with-mssql=/usr/local/freetds --with-php-config=/usr/local/php/bin/php-config
   # make -j 4
   # cp .libs/mssql.so /PHP_Extension_디렉토리
   # vi /usr/local/php/lib/php.ini
     extension = mssql.so --> 주석 풀기
   # apache 재기동


모듈 설치 확인
phpinfo - mssql 항목 확인, php -i 옵션으로 확인

   # /usr/local/php/bin/php -i | grep mssql
   mssql
   mssql.allow_persistent => On => On
   mssql.batchsize => 0 => 0
   mssql.charset => no value => no value
   mssql.compatability_mode => Off => Off
   mssql.connect_timeout => 5 => 5
   mssql.datetimeconvert => On => On
   mssql.max_links => Unlimited => Unlimited
   mssql.max_persistent => Unlimited => Unlimited
   mssql.max_procs => Unlimited => Unlimited
   mssql.min_error_severity => 10 => 10
   mssql.min_message_severity => 10 => 10
   mssql.secure_connection => Off => Off
   mssql.textlimit => Server default => Server default
   mssql.textsize => Server default => Server default

   mssql.timeout => 60 => 60


MSSQL 접속 PHP 샘플

<?php
    putenv("FREETDSCONF=/usr/local/freetds/etc/freetds.conf");
    putenv("TDSVER=80");


     $link = mssql_connect('123.123.123.123', '디비계정', '디비비밀번호');
     if (!$link) {
        echo 'DB connection fail.';
     } else {
      echo 'DB connection Success.';

     }
     mssql_close($link);
 ?>

Posted by 멋지다마라송


티스토리 툴바