Linux下php的mssql扩展安装

1、下载源码FreeTDS

wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz

2、安装FreeTDS

tar -zxvf freetds-stable.tgz
cd freetds-0.82
 ./configure --prefix=/usr/local/webserver/freetds-0.82 --with-tdsver=8.0 --enable-msdblib
make
make install
vi /usr/local/webserver/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
        client charset = UTF-8

3、编译mssql扩展

cd /data/software/php-5.2.8/ext/mssql
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-mssql=/usr/local/webserver/freetds-0.82/
make
make install

4、加入php.ini

extension = mssql.so

5、重启验证

[root@mssql]# /usr/local/webserver/php/bin/php -m
[PHP Modules]
bcmath
ctype
curl
date
dom
eAccelerator
filter
gd
hash
iconv
imagick
json
libxml
mbstring
mcrypt
memcache
memcached
mssql
mysql
mysqli
openssl
pcre
PDO
pdo_sqlite
posix
Reflection
session
shmop
SimpleXML
soap
sphinx
SPL
SQLite
standard
sysvsem
tokenizer
xhprof
xml
xmlreader
xmlwriter
zip
zlib
 
[Zend Modules]
eAccelerator

6、测试连接

<?php   
header("Content-type: text/html; charset=utf-8");   
$msdb=mssql_connect("mssql.yourdomain.com:1433","username","password");   
if (!$msdb) {   
        echo "connect sqlserver error";   
        exit;   
}   
mssql_select_db("database_name",$msdb);   
$result = mssql_query("SELECT top 5 * FROM table", $msdb);   
while($row = mssql_fetch_array($result)) {   
        var_dump($row);   
}   
mssql_free_result($result);   
?>

还没有评论,快来抢沙发!

发表评论

  • 😉
  • 😐
  • 😡
  • 😈
  • 🙂
  • 😯
  • 🙁
  • 🙄
  • 😛
  • 😳
  • 😮
  • emoji-mrgree
  • 😆
  • 💡
  • 😀
  • 👿
  • 😥
  • 😎
  • ➡
  • 😕
  • ❓
  • ❗
  • 66 queries in 0.414 seconds