linux wdcp連接sqlsever

1.安裝FreeTDS

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz

tar -zxvf freetds-patched.tar.gz

ll

# drwxr-xr-x 10 root  root     4096 Apr  3 17:16 freetds-1.00.84
# -rw-r--r--  1 root  root  2913320 Apr  3 17:07 freetds-patched.tar.gz

cd freetds-1.00.84

[root@iztkatyiq1z1ltz freetds-1.00.84]# ll
total 2284
-rw-r--r--  1 11027 11027 137693 Apr  2 17:00 aclocal.m4
-rw-r--r--  1 11027 11027   2772 May 19  2016 AUTHORS
-rwxr-xr-x  1 11027 11027   1576 May  6  2015 autogen.sh
-rw-r--r--  1 11027 11027    309 May 19  2016 BUGS
-rw-r--r--  1 11027 11027  23345 Apr  2 17:00 ChangeLog
-rw-r--r--  1 11027 11027  14760 Jun  9  2017 CMakeLists.txt
-rwxr-xr-x  1 11027 11027   7333 Apr  2 17:00 compile
-rwxr-xr-x  1 11027 11027  43940 Apr  2 17:00 config.guess
-rw-r--r--  1 root  root  272543 Apr  3 17:15 config.log
-rwxr-xr-x  1 11027 11027  18343 May 15  2015 config.rpath
-rwxr-xr-x  1 root  root   72697 Apr  3 17:15 config.status
-rwxr-xr-x  1 11027 11027  36383 Apr  2 17:00 config.sub
-rwxr-xr-x  1 11027 11027 689741 Apr  2 17:00 configure
-rw-r--r--  1 11027 11027  30429 Apr  2 17:00 configure.ac
-rw-r--r--  1 11027 11027  18092 May 19  2016 COPYING
-rw-r--r--  1 11027 11027  25383 May 19  2016 COPYING.LIB
-rwxr-xr-x  1 11027 11027  23566 Apr  2 17:00 depcomp
drwxr-xr-x  5 root  root    4096 Apr  3 17:16 doc
-rw-r--r--  1 11027 11027   1281 Feb  5  2017 freetds.conf
-rw-r--r--  1 root  root    4368 Apr  3 17:15 freetds.spec
-rw-r--r--  1 11027 11027   4372 May 19  2016 freetds.spec.in
drwxr-xr-x  4 root  root    4096 Apr  3 17:15 include
-rw-r--r--  1 11027 11027    756 May 19  2016 INSTALL
-rwxr-xr-x  1 11027 11027   6760 Apr  2 17:00 install-sh
-rw-r--r--  1 11027 11027   2359 May  6  2015 interfaces
-rwxr-xr-x  1 root  root  342693 Apr  3 17:15 libtool
-rw-r--r--  1 11027 11027    370 May  6  2015 locales.conf
-rw-r--r--  1 11027 11027 324089 Apr  2 17:00 ltmain.sh
drwxr-xr-x  2 root  root    4096 Apr  3 17:10 m4
-rw-r--r--  1 root  root   28983 Apr  3 17:15 Makefile
-rw-r--r--  1 11027 11027   2031 May 19  2016 Makefile.am
-rw-r--r--  1 11027 11027  29364 Apr  2 17:00 Makefile.in
drwxr-xr-x  2 root  root    4096 Apr  3 17:15 misc
-rwxr-xr-x  1 11027 11027   6872 Apr  2 17:00 missing
-rwxr-xr-x  1 11027 11027    729 Sep 23  2015 mkinstalldirs
-rw-r--r--  1 11027 11027  24295 May 19  2016 NEWS
-rw-r--r--  1 root  root     762 Apr  3 17:16 PWD
-rw-r--r--  1 11027 11027    762 May  6  2015 PWD.in
-rw-r--r--  1 11027 11027   3081 May 19  2016 README
drwxr-xr-x  2 root  root    4096 Apr  3 17:16 samples
drwxr-xr-x 10 root  root    4096 Apr  3 17:15 src
-rw-r--r--  1 11027 11027    828 May 19  2016 tds.dox
-rwxr-xr-x  1 11027 11027   4640 Apr  2 17:00 test-driver
-rw-r--r--  1 11027 11027   1048 May 19  2016 Thanks-1.0
-rw-r--r--  1 11027 11027   5813 May 19  2016 TODO
drwxr-xr-x  2 root  root    4096 Apr  3 17:15 vms
drwxr-xr-x  3 root  root    4096 Apr  3 17:15 win32
[root@iztkatyiq1z1ltz freetds-1.00.84]# 

sqlsever2008 with-tdsver 要等於 7.3

 ./configure --prefix=/usr/local/freetds --with-tdsver=7.3 --enable-msdblib
 make && make install

配置FreeTDS

# cd ../

# echo "/usr/local/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
# ldconfig

驗證FreeTDS版本

這一步非常重要,通過纔可以繼續,不然後面的步驟都是無意義的。

首先看看版本信息

 # /usr/local/freetds/bin/tsql -C

Compile-time settings (established with the "configure" script)
Version: freetds v1.00.84
 freetds.conf directory: /usr/local/freetds/etc
 MS db-lib source compatibility: yes
Sybase binary compatibility: no
  Thread safety: yes
  iconv library: yes
TDS version: 7.3
  iODBC: no
   unixodbc: no
  SSPI "trusted" logins: no
   Kerberos: no
OpenSSL: yes
 GnuTLS: no
   MARS: no

測試數據庫是否聯通

/usr/local/freetds/bin/tsql -H 數據庫服務器IP -p 端口號 -U 用戶名 -P 密碼

 [root@iztkatyiq1z1ltz freetds-1.00.84]# /usr/local/freetds/bin/tsql -H 111.2xx.2xx.2xx -p 56xx -U xxx -P xxx
 locale is "en_US.UTF-8"
 locale charset is "UTF-8"
 using

添加PHP擴展pdo的pdo_dblib

1.確定phpize是否可用

[root@iztkatyiq1z1ltz freetds-1.00.84]# phpize -v
Configuring for:
PHP Api Version: 20100412
Zend Module Api No:  20100525
Zend Extension Api No:   220100525

如果報沒有phpize該命令的話可以嘗試用php的全路徑 如wdcp php 5.6

/www/wdlinux/phps/56/bin/phpize -v

2.下載 php5.6包到dblib文件下

wget hk2.php.net/distributions/php-5.6.35.tar.bz2
    
tar jxvf php-5.6.35.tar.bz2

cd php-5.6.35/ext/pdo_dblib/

3.執行phpize

/www/wdlinux/phps/56/bin/phpize

如果報Cannot find config.m4錯誤請看有pdo_dblib沒有config.m4文件。如果沒有cp一份裏面帶.m4的文件重命名爲config.m4 然後再/www/wdlinux/phps/56/bin/phpize

./configure --with-php-config=/www/wdlinux/phps/56/bin/php-config --with-pdo-dblib=/usr/local/freetds/

/www/wdlinux/phps/56/bin/php-config必須是要修改php.ini所對應的php-config

make && make install

4.在對應的php.ini裏面添加配置

 extension = pdo_dblib.so  

5.重啓php

6.phpinfo()

出現pdo_dblib配置就完成配置了

7.php連接代碼 private function linksever(){ header("content-type:text/html;charset=utf-8");

try{
if(PATH_SEPARATOR==':'){
$db = new \PDO("dblib:host=111.xxx.xxx.xxx:56xx;dbname=","usenamexxx","pwdxxx");
}else{
$db = new \PDO("sqlsrv:Server=111.xxx.xxx.xxx,56xx;Database=xxx","usenamexxx","pwdxxx");
}

}catch(PDOException $e){
echo "ERROR:".$e->getMessage();
exit;
}
//if($db)echo "OK!Connected!<br />";

return $db;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章