1.编译安装FreeTDS
从官网下载最新的版本 ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
#wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
#tar -zxvf freetds-patched.tar.gz
#cd freetds-0.95.95
#./configure --prefix=/usr/local/freetds --with-tdsver=7.3 --enable-msdblib
#make && make install
#echo "/usr/local/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
验证:
链接数据库验证:
#/usr/local/freetds/bin/tsql -H "ip" -p 1433 -U "sa" -P"123456"
2.添加PHP扩展mssql和pdo的pdo_dblib
#cd php-5.4.26/ext/mssql/
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config --with-mssql=/usr/local/freetds/
#make && make install
#cd php-5.4.26/ext/mssql/pdo_dblib/
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-dblib=/usr/local/freetds/
#make && make install
3.在php.ini配置文件中增加一下配置
extension = "mssql.so"
extension ="pdo_dblib.so"
4.验证(文件保存为sql.php):
<?php
$con=mssql_connect("ip:port","user","password");
if ($con)
{
echo "连接成功";
}
else
echo "连接失败";
?>
执行该程序 #php sql.php
亲测可以实现php连接sqlserver。