#1 mebtime
先下载安装lnmp1.2,具体请到lnmp.org,上边有教程下载FreeTds
编译安装freetds:wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-0.91.102.tar.gz
tar -zxvf freetds-0.91.102.tar.gz--enable-dbmfix这个选项会报错,但最后还是用起来了,所以这个参数就去掉吧
cd freetds-0.91.102
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared --enable-static
make && make install
更正路径:./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared --enable-static
8.0编译会自动变成5.0 奇怪。。。。。(我的变成7.0)
下面修改freetds配置文件:
freetds/etc/freetds.conf
在A typical Microsoft server 下面添加我们要连接数据库的一些信息,在后边加上就行
[win12r2]
host = 192.168.1.119
port = 1433
tds version = 7.0
client charset = UTF-8
测试链接,
运行./tsql -C 检查,这个tsql是在freetds目录下,找一下就看到了,是在tsql这个的目录下执行这个命令,要不然会报错的./tsql -H ip -p 1433 -U sa -P pw
=====================================================================
安装php之pdo_dblib扩展:
cd lnmp1.2/src/php-5.5.25/lib/php/ext/pdo_dblib //切换到lnmp1.2的安装源目录下的pdo_dblib扩展目录
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-dblib-config=/usr/local/freetds
把提示生成的pdo_dblib.so移到/usr/local/php/lib/php/extensions/下(你php.ini里extension_dir是哪个目录就移到哪个目录),然后在php.ini里加上extensions=pdo_dblib.so;,重新启动lnmp即可.
=================================
[root@test PDO_DBLIB-1.0] ./configure –with-php-config=/usr/bin/php-config –with-pdo_dblib=/usr/local/freetds
configure: error: Directory /usr/local/freetds is not a FreeTDS installation directory
解决办法,执行命令:
touch /usr/local/freetds/include/tds.h
touch /usr/local/freetds/lib/libtds.a
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo_dblib=/usr/local/freetds
时就ok了=================================
测试代码(前提你懂的):
$db = new PDO("dblib:host=192.168.1.111;dbname=test","sa","Password");
$sql = "select * from t";
$res = $db->query($sql);
foreach ($res as $row){
print_r($row);
}
2015-10-12 10:45:16