溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

linux下php如何加裝mssql模塊

發(fā)布時(shí)間:2022-05-06 10:24:53 來源:億速云 閱讀:183 作者:iii 欄目:大數(shù)據(jù)

這篇文章主要講解了“l(fā)inux下php如何加裝mssql模塊”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“l(fā)inux下php如何加裝mssql模塊”吧!

1、安裝配置freetds

復(fù)制代碼 代碼如下:

wget http://mirrors.xmu.edu.cn/ubuntu/archive/pool/main/f/freetds/freetds_0.82.orig.tar.gz
tar zxf freetds_0.82.orig.tar.gz
cd freetds_0.82
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 -–enable-msdblib -–enable-dbmfix -–with-gnu-ld -–enable-shared -–enable-static
make && make install

2、編譯php的mssql模塊

復(fù)制代碼 代碼如下:

cd /path/to/php/source 進(jìn)入php源碼目錄
cd ext/mssql 進(jìn)入mssql模塊源碼目錄
/usr/local/webserver/php/bin/phpize 生成編譯配置文件
./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-mssql=/usr/local/freetds
make
make install
編譯完成生成 mssql.so,修改php.ini,將該模塊載入:
extension=”/path/to/extension/mssql.so”

3、配置mssql

復(fù)制代碼 代碼如下:

cd /usr/local/freetds/etc
編輯文件:
vi 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
client charset = utf-8 #加入
#加入
[server2005]
host = 192.168.x.x
port = 1433
tds version = 7.2

4、測試php連接mssql

復(fù)制代碼 代碼如下:

<?php
try {
$hostname='218.x.x.x';//注意,這里和上面不同,要直接用ip地址或主機(jī)名
$port=1433;//端口
$dbname="user";//庫名
$username="database";//用戶
$pw="passwd";//密碼
$dbh= new pdo("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (pdoexception $e) {
echo"failed to get db handle: ".$e->getmessage() ."n";
exit;
}
echo'connent mssql succeed';
$stmt=$dbh->prepare("select * from z_2010pinjiu_user");
$stmt->execute();
while ($row=$stmt->fetch()) {
print_r($row);
}
unset($dbh); unset($stmt);
?>

感謝各位的閱讀,以上就是“l(fā)inux下php如何加裝mssql模塊”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對linux下php如何加裝mssql模塊這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI