標籤:php串連sql_server資料庫
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
驗證:
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="https://mmbiz.qlogo.cn/mmbiz_png/EeFBufvNbwgyxdrOzwXmW2YuaYMeKU1xsbaG7DVbqCTZ5DlZ1UVaKkk2s5pXKO5LxJQXYpswUJ5MbyVeJAPlHQ/0?wx_fmt=png" style="margin:0px;padding:0px;height:auto;" alt="0?wx_fmt=png" />
連結資料庫驗證:
#/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。
本文出自 “Linux” 部落格,請務必保留此出處http://syklinux.blog.51cto.com/9631548/1889087
php串連sql_server資料庫