您的位置:首页 > 编程语言 > PHP开发

PHP添加mssql模块,连接sql server数据库

2012-03-27 10:02 447 查看
一、 下载/安装Freetds

wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz tar zxvf freetds-stable.tgz
cd freetds-0.82/
./configure --prefix=/opt/freetds --with-tdsver=8.0 --enable-msdblib
make && make install
cd ../
echo "/opt/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
ln -s /opt/freetds/lib/libsybdb.so.5.0.0 /opt/freetds/lib/libsybdb.so.4
/sbin/ldconfig

二、 编辑配置文件

vi /opt/freetds/etc/freetds.conf
[global]
# TDS protocol version
;       tds version = 4.2

# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

# Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting ’text size’ to a more reasonable limit
text size = 64512

host = mssql.yourdomain.com
port = 1433
tds version = 8.0     #连接mssql2000 对应8.0的版本
client charset = UTF-8

三、 进入PHP源码包目录,将mssql模块以打补丁的形式添加

cd /root/php-5.3.3/ext/mssql/
/opt/php/bin/phpize
./configure --with-php-config=/opt/php/bin/php-config --with-mssql=/opt/freetds/
make && make install

四、 在php.ini配置文件中增加mssql.so

#vi php.ini

extension = "mssql.so"

五、 测试

<?php
$conn=mssql_connect('hostip','username','password') or die('connect error');
mssql_select_db('databasename') or die ('selected error');
?>


或者查看phpinfo()输出有没有mssql模块
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: