출처 : http://woolab.net/140121930250

php와 mssql 연동

1. freetds 설치
# wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
# tar xvfz freetds-stable.tgz
# cd freetds-0.82
# ./configure --prefix=/usr/local/freetds \
--with-tdsver=8.0 \
--disable-odbc \
--disable-debug \
--enable-dbmfix \
--enable-msdblib
# make
# make install

2. php 컴파일
# ./configure ...... --with-mssql=/usr/local/freetds
* error: Directory /usr/local/freetds is not a FreeTDS installation directory 오류
# cp /usr/local/freetds-0.82/include/tds.h /usr/local/freetds/include/
* error: Could not find /usr/local/freetds/lib/libtds.a|so 오류
# cp /usr/local/freetds-0.82/src/tds/.lib/libds.a /usr/local/freetds/lib/
# make
# make install
# /usr/local/apache2/bin/apachectl restart

3. 확인 및 설정
- phpinfo
> mssql 확인
- php.ini
> mssql.charset =  "UTF-8"

4. yum 설치
# yum install -y freetds php-mssql
# /etc/freetds.conf
> [mssql_database]
> host = xxx.xxx.xxx.xxx
> port = 1433
> tds version = 8.0
> client charset = UTF-8

5. 접속 확인
# tsql -H xxx.xxx.xxx.xxx -p 1433 -U db_user_name -P db_user_password
> locale is "en_US.UTF-8"
> locale charset is "UTF-8"
> 1> select * from table_name
> 2> go

6. php 테스트
<?
$db_conn=mssql_connect("mssql_database", "db_user_name", "db_user_password");
mssql_select_db("database_name", $db_conn);
$sql="select count(*) from table_name";
$rs=mssql_query($sql, $db_conn);
echo "result";
echo mssql_result($rs, 0, 0);
mssql_close($db_conn);
?>

'Dev > PHP' 카테고리의 다른 글

컴파일 오류시 대처하기  (0) 2011.05.13
php 컴파일에러  (0) 2011.05.13
FreeTDS 설치 (PHP와 MS-SQL 연동)  (0) 2011.05.13
CentOS 64bit Apache PHP 컴파일 설치  (2) 2011.05.13
PHP Configure Option  (0) 2011.05.13

 

FreeTDS 설치 (PHP와 MS-SQL 연동)


Apache + PHP 사용시 원격 MSSQL 데이터베이스에 접근 하는 방법중 FreeTDS를 이용한 방법이 있습니다.
설치법도 간단하고 간단한 설정법으로 한글깨짐현상도 해결할 수 있습니다.


[설치]
/usr/local/src#
 wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz

/usr/local/src# tar xvfpz freetds-stable.tgz

/usr/local/src/freetds# ./configure 
--prefix=/usr/local/freetds 
--with-tdsver=8.0 
--disable-odbc 
--disable-debug 
--enable-dbmfix 
--enable-msdblib

/usr/local/src/freetds# make

/usr/local/src/freetds#
 make install


[참고]

mssql 2005 의 경우 --with-tdsver=8.0

mssql 2000 의 경우 --with-tdsver=8.0

mssql 7.0 의 경우 --with-tdsver=7.0

mssql 6.0 의 경우 --with-tdsver=4.2

 

configure 단계에서 'Directory /usr/local/freetds is not a FreeTDS installation directory' 라는 메시지가 나올경우
# cp /usr/local/src/freetds/include/tds.h /usr/local/freetds/include/
또는
# cp /usr/local/src/freetds/src/tds/.libs/tds.h /usr/local/freetds/include/
tds.h 파일을 설치된 디렉토리에 복사한다.


[설치 계속]

freetds.conf 파일에 client charset=EUC-KR을 추가하여 한글깨짐 현상을 막을 수 있습니다..
( /usr/local/freetds/etc/freetds.conf )

[global]
client charset = EUC-KR


PHP 설치

/usr/local/src/php# ./configure 
--prefix=/usr/local/php 
--with-apxs2=/usr/local/bin/apxs
--with-sybase=/usr/local/freetds
--with-mssql=/usr/local/freetds    <- 하단 참고사항 확인


/usr/local/src/php# make
/usr/local/src/php# make install

[참고] php 5.X --with-mssql 오류시 해결 방안  

php 5.X에서 mssql연동을 위해 freetds를 설치할 경우에  php configure에 --with-mssql=/usr/local/freetds로 주었을때 해당 경로에 설치가 되어있음에도 불구하고 해당 경로에 설치가 되어있지 않다고 나오는 경우가 발생합니다.

에러 메세지
error Directory /usr/local/freetds is not a FreeTDS installation directory

해당 문제는 tds.h, libtds.a가 해당 설치경로에 있지 않아 설치되어 있는데도 설치되어 있지 않은것으로 인식되는 문제로 보입니다.

아래와 같이 해당 파일들을 경로로 복사해 주면 문제가 해결 됩니다.

cp /usr/local/src/freetds-xxx/include/tds.h /usr/local/freetds/include
cp /usr/local/src/freetds-xxx/src/tds/.libs/libtds.a /usr/local/freetds/lib

위와 같이 한 후에 make 과정중에 sysbase 오류가 발생한다면 configure 시에 --with-mssql과 --with-sybase를 같이 넣어 줍니다.


[참고 - PHP와 MS-SQL연동을 위해 odbc를 이용한 방법 - 오래된메뉴얼]
http://cafe.naver.com/webmas.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=1000

 

 

[출처] 정상을 위한 독주2 (http://blueb.net/blog/1321) | 블루비

[추가/수정] 차동훈 (http://system.neulwon.com)

 

--------------------------------------------------------------------------------------

 

php - mssql 연동 테스트 소스

 

<?

$connection=mssql_connect("MyServer","msconn","msconn");
print ("db open");
mssql_connect($connection);
print ("db close");
$status = mssql_select_db("master",$connection);

if (!$status) {
$errNO = mssql_errno($connection);
$errMSG = mssql_errno($connection);

echo("데이터 베이스 연결 실패");
echo("에러메세지 $errNO : $errMSG");
exit;
}


$que = mssql_query("select * from sysfiles");
$row = mssql_fetch_row($que);

echo"

$row[0] $row[1] $row[2]";

echo"
성공";
?>

[발췌] Nugi's World | 야서누기 (http://blog.daum.net/evasuri/10243883)

'Dev > PHP' 카테고리의 다른 글

php 컴파일에러  (0) 2011.05.13
php mssql 연동 (freetds)  (0) 2011.05.13
CentOS 64bit Apache PHP 컴파일 설치  (2) 2011.05.13
PHP Configure Option  (0) 2011.05.13
PHP 암호화 함수정리  (0) 2011.05.07

+ Recent posts