linux下配置连接mssql环境

 这里我们采用freeTDS程序库,实现linux下访问微软SQL SERVER数据库,php通过mssql.so库文件实现连接mssql

操作步骤如下:

       1.下载freeTDS

http://www.ibiblio.org/pub/Linux/ALPHA/freetds/old/0.63/freetds-0.63.tar.gz

tar xf freetds-0.63.tar.gz

./configure --prefix= --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld

--enable-shared --enable-static

make && make install

(-prefix为设置FreeTDS的安装目录,--with-tdsver是设置TDS版本,--enable-msdblib为是否允许Microsoft数据库函数库)

       vim  /etc/profile

        中加入export PATH="$PATH:/usr/local/freetds/bin"

        source /etc/profile  是修改的系统变量生效

2.将freetds库加入系统库缓存

echo “/usr/local/freetds/lib”>>/etc/ld.so.conf

ldconfig命令使其生效

3、配置freetds(可省)

[root@ ~]# cat /usr/local/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 = xxx.xxx.xxx.xxx(mssql地址)

port = 1433
      tds version = 8.0
      client charset = UTF-8

4.增加mssql扩展

cd  /usr/src/lnmp/php-5.3.10/ext/mssql

/usr/local/bin/phpize

./configure  --with-php-config=/usr/local/bin/php-config  --with-mssql=/usr/local/freetds

make && make install

ls  /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/mssql.so

vim /usr/local/php/etc/php.ini

添加extension=mssql.so

      测试:

<?php
$ms = mssql_connect('192.168.1.111,9201','usernanme','passwd',false);
var_dump($ms);
?>

你可能感兴趣的:(mssql扩展)