linux下php加裝mssql模塊的方法
更新時(shí)間:2011年05月02日 13:33:30 作者:
在linux 下的php連接mssql,就需要安裝第三方的freetds了。需要的朋友可以參考下。
1、安裝配置freetds
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模塊
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
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、測(cè)試php連接mssql
<?php
try {
$hostname='218.x.x.x';//注意,這里和上面不同,要直接用IP地址或主機(jī)名
$port=1433;//端口
$dbname="user";//庫(kù)名
$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);
?>
復(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、測(cè)試php連接mssql
復(fù)制代碼 代碼如下:
<?php
try {
$hostname='218.x.x.x';//注意,這里和上面不同,要直接用IP地址或主機(jī)名
$port=1433;//端口
$dbname="user";//庫(kù)名
$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);
?>
您可能感興趣的文章:
- Ubuntu中為Android增加硬件抽象層(HAL)模塊訪問(wèn)Linux內(nèi)核驅(qū)動(dòng)程序
- 解析Linux內(nèi)核的基本的模塊管理與時(shí)間管理操作
- Linux內(nèi)核模塊和驅(qū)動(dòng)的編寫(xiě)
- Linux下給nginx安裝waf模塊
- Python2.x利用commands模塊執(zhí)行Linux shell命令
- python下paramiko模塊實(shí)現(xiàn)ssh連接登錄Linux服務(wù)器
- Linux下PHP安裝mcrypt擴(kuò)展模塊筆記
- linux下為nginx添加jvmroute模塊的方法
- Linux內(nèi)核設(shè)備驅(qū)動(dòng)之Linux內(nèi)核模塊加載機(jī)制筆記整理
相關(guān)文章
解決navicat連接不上linux服務(wù)器上的mysql問(wèn)題
這篇文章主要介紹了navicat連接不上linux服務(wù)器上的mysql的解決辦法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10關(guān)于CentOS 7下sqlite3找不到的問(wèn)題解決
這篇文章主要給大家介紹了關(guān)于CentOS 7下sqlite3找不到問(wèn)題的解決方法,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧。2017-07-07怎么禁用 Ubuntu 服務(wù)器中終端歡迎消息中的廣告
這篇文章主要介紹了怎么禁用 Ubuntu 服務(wù)器中終端歡迎消息中的廣告,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-11-11Linux+Nginx+Php架設(shè)高性能WEB服務(wù)器
來(lái)自wiki.nginx.org的關(guān)于Nginx的介紹2009-05-05CentOS 安裝軟件出現(xiàn)錯(cuò)誤:/lib/ld-linux.so.2: bad ELF interpreter 解決
這篇文章主要介紹了CentOS 安裝軟件出現(xiàn)錯(cuò)誤:/lib/ld-linux.so.2: bad ELF interpreter 解決的相關(guān)資料,需要的朋友可以參考下2017-03-03