linux下php加裝mssql模組的方法

來源:互聯網
上載者:User

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 進入PHP源碼目錄
cd ext/mssql 進入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、測試php串連mssql
複製代碼 代碼如下:<?php
try {
$hostname='218.x.x.x';//注意,這裡和上面不同,要直接用IP地址或主機名稱
$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);
?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.