一、 下载/安装Freetds

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

二、 编辑配置文件

 
  
  1. vi /opt/freetds/etc/freetds.conf     
  2. [global]      
  3.         # TDS protocol version      
  4. ;       tds version = 4.2      
  5.      
  6.         # Whether to write a TDSDUMP file for diagnostic purposes      
  7.         # (setting this to /tmp is insecure on a multi-user system)      
  8. ;       dump file = /tmp/freetds.log      
  9. ;       debug flags = 0xffff     
  10.      
  11.         # Command and connection timeouts      
  12. ;       timeout = 10     
  13. ;       connect timeout = 10     
  14.      
  15.         # If you get out-of-memory errors, it may mean that your client      
  16.         # is trying to allocate a huge buffer for a TEXT field.      
  17.         # Try setting ’text size’ to a more reasonable limit      
  18.         text size = 64512     
  19.      
  20.         host = mssql.yourdomain.com      
  21.         port = 1433     
  22.         tds version = 8.0     #连接mssql2000 对应8.0的版本 
  23.         client charset = UTF-8     

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

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

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

#vi php.ini

extension = "mssql.so"

五、 测试

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

或者查看phpinfo()输出有没有mssql模块