最開始想使用 pdo_sqlsrv 拓展,可是一直沒成功,本文采用的是 pdo_dblib + freetds。
php
環境:CentOS 6.八、PHP 5.6.20html
freetdslinux
1 wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.109.tar.gz 2 tar -xzf freetds-1.00.109.tar.gz 3 cd freetds-1.00.109/ 4 ./configure --prefix=/datas/soft/freetds --enable-msdblib --with-tdsver=7.1 5 make 6 make install 7 /datas/soft/freetds/bin/tsql -C
pdo_dblibsql
1 cd ~/php-5.6.20/ext/pdo_dblib 2 /datas/soft/php56/bin/phpize 3 ./configure --with-php-config=/datas/soft/php56/bin/php-config --with-pdo-dblib=/datas/soft/freetds 4 make 5 make install 6 vim /datas/soft/php56/etc/php.ini 7 extension = "pdo_dblib.so" 8 php --ri pdo_dblib
測試代碼數據庫
1 $db = new PDO ("dblib:host=IP:端口;dbname=數據庫名","用戶名","密碼"); 2 $stmt = $db->prepare("SELECT top 5 * FROM my_table"); 3 $stmt->execute(); 4 while ($row = $stmt->fetch()) { 5 var_dump($row); 6 }
另外,我這邊用的是 php-5.6.20 安裝包裏自帶的拓展包去編譯 pdo_dblib,偶然有一次是從 http://pecl.php.net/package/PDO_DBLIB 下載的,會出現如下錯誤vim
1 checking for re2c... no 2 configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. 3 checking for gawk... gawk 4 checking for PDO_DBLIB support via FreeTDS... yes, shared 5 configure: error: Directory /datas/soft/freetds is not a FreeTDS installation directory
參考資料post
https://blog.csdn.net/lanwilliam/article/details/79557119
https://blog.csdn.net/qq_20259383/article/details/77838209
https://www.aliyun.com/jiaocheng/126744.html
http://www.freetds.org
https://blog.slogra.com/post-421.html
https://sourceforge.net/projects/re2c/files/
https://www.linuxidc.com/Linux/2008-09/15686.htm測試