출처 : 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

+ Recent posts