Linux下php串連SQLServer 2000資料庫的配置方法

來源:互聯網
上載者:User

說明:

Linux伺服器系統:CentOS 5.5

Web環境:LAMP或者LNMP

Windows伺服器系統:Windows Server 2003

Windows伺服器IP地址:192.168.21.134

資料庫環境:SQL Server 2000資料庫

資料庫帳號:sa

資料庫密碼:123456

實現目的:Linux伺服器中的php程式能夠串連到Windows伺服器中的SQL Server 2000資料庫

具體步驟:

一、在Linux伺服器中安裝freetds

1、安裝編譯工具及驅動程式

yum install make apr* autoconf automake gcc gcc-c++ wget

2、安裝unixODBC驅動程式

yum -y install unixODBC unixODBC-devel

3、安裝freetds

cd /usr/local/src

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz #下載

gunzip freetds-stable.tgz #解壓

tar -xvf freetds-stable.tar

cd freetds-0.91

./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --with-unixodbc=/usr --enable-msdblib #配置

make #編譯

make install #安裝

4、配置freetds

cp /usr/local/freetds/etc/freetds.conf /usr/local/freetds/etc/freetds.confbak #備份原有檔案

vi /usr/local/freetds/etc/freetds.conf #在最後位置修改編輯以下內容

系統營運 www.osyunwei.com 溫馨提醒:qihang01原創內容著作權,轉載請註明出處及原文鏈

[192.168.21.134]
host = 192.168.21.134 #SQL Server 2000伺服器位址
port = 1433 #SQL Server 2000資料庫連接埠
tds version = 8.0 #8.0代表資料庫版本為SQL Server 2000
client charset = UTF-8 #設定字元集

5、測試freetds

/usr/local/freetds/bin/tsql -S 192.168.21.134 -U sa #測試,提示輸入資料庫密碼,出現下面介面,配置成功

cd /usr/local/freetds/bin

./tsql -S 192.168.21.134 -p 1433 -U sa -P 123456 -D master #測試,出現下面介面,配置成功

二、配置Linux php串連SQL Server 2000資料庫

1、php是用yum命令線上安裝

yum install php-mssql #安裝php-mssql擴充,如果提示沒有此安裝包,請先配置第三方yum源

wget http://www.atomicorp.com/installers/atomic #下載

sh ./atomic #安裝

yum install php-mssql #再次執行

2、php是用源碼編譯安裝

cd /usr/local/src/php-5.3.15/ext/mssql #進入php源碼包的ext下mssql目錄

/usr/local/php5/bin/phpize

./configure --with-php-config=/usr/local/php5/bin/php-config --with-mssql=/usr/local/freetds #配置

注意:--with-mssql=/usr/local/freetds #是指freetds的安裝路徑

make #編譯

make install #安裝

vi /usr/local/php5/etc/php.ini #編輯,在最後位置添加下面一行

extension = "mssql.so"

:wq! #儲存退出

3、重啟LAMP或者LNMP

service httpd restart #重啟apache

service php-fpm restart #重啟php-fpm

三、測試php串連SQL Server 2000資料庫

進入php程式目錄,建立一個測試檔案

cd /usr/local/nginx/html #請改為自己的網站目錄

vi sql.php #添加以下內容

<?php

$mssql=mssql_connect("192.168.21.134","sa","123456");

if ($mssql) {

echo "Connent Mssql Succeed";

}

else {

echo "connent Mssql Error!";

}

?>

:wq! #儲存退出

注意:這裡的192.168.21.134必須要和/usr/local/freetds/etc/freetds.conf中的[192.168.21.134]完全一樣

在瀏覽器中開啟,出現下面的介面,串連成功

可以在建立一個檔案

vi index.php

<?php

phpinfo();

?>

在瀏覽器中開啟,能找到mssql,說明配置成功,如所示

至此,Linux下php串連SQL Server 2000資料庫配置完成

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.