当前位置:操作系统 > Unix/Linux >>

在linux下的freetds安装方法

第一步:编译安装freetds: 810635
得到freetds-0.53.tgz后
cp freetds-0.53.tgz /tmp/. (拷贝freetds包到/tmp目录)
cd /tmp (进入目录)
tar zxvf freetds-0.53.tgz (解压)
cd freetds-0.53 (进入解压后目录)
./configure –prefix=/usr/local/freetds --with-tdsver=8.0
gmake (生成Makefile,make也可以)
gmake install (安装)
configure说明:--prefix=/usr/local/freetds是指安装到/usr/local/freetds这个目录中
--with-tdsver=8.0是指安装tds 8.0版本(如果没有加这个参数,则按照默认编译为5.0。5.0连接数据库的端口是4000,而不是SQLServer的1433)

第二步:重新编译PHP4
./configure [--with-apxs --with-mysql...] --with-sybase=/usr/local/freetds(请注意是sybase)
make
make install
第三步:配置freetds
vi /usr/local/freetds/etc/freetds.conf
具体配置见该文件中的说明
典型配置:
[sqlserver]
host = host (你的SQLServer机器名字或者IP地址)
port = 1433 (端口)
tds version = 8.0
在这个配置文件中可以配置Windows域登陆或者SQLServer账号登陆两种方式
第四步:配置php.ini文件
找到 ;extension=mssql80.so
将注释;去掉成
extension=mssql70.so
第五步:测试是否能用:
# bin/tsql -S MyServer2k -H 192.168.0.32 -p 1433 -U sa -P password
1> use gameDB
2> go
1> select count(*) from t_ip
4
1> quit
如果是用LINUXODBC连时改如下:
1.先安装ODBC:
# tar vxzf unixODBC-2.2.8.tar.gz
# cd unixODBC-2.2.8
# ./configure --prefix=/usr/local/unixODBC
# make
# make install
2.配置FREETDS时改成如下语句:
# ./configure --prefix=/usr/local/freetds --with-unixodbc=/usr/local/unixODBC --with-tdsver=8.0
3.配置ODBC:
# cd /usr/local/unixODBC
向ODBC添加SQLServer驱动
# vi etc/odbcinst.ini[code]写入如下内容:[code][TDS] ;驱动名称
Description = MS-SQLServer ;描述
Driver = /usr/local/freetds/lib/libtdsodbc.so ;驱动程序
Setup = /usr/local/freetds/lib/libtds.so ;
FileUsage = 1
保存退出
添加DSN
# vi etc/odbc.ini
写入如下内容
[123] ;DSN名称
Driver = TDS ;ODBC驱动
Server = 192.168.0.32 ;服务器IP
Database = gameDB ;要使用的数据库
Port = 1433 ;端口
Socket =
Option =
Stmt =
保存并退出,测试ODBC的连接
# bin/isql -v 123 sa password
SQL> select count(*) from t_ip
+----------+
| |
+----------+
| 4 |
+----------+
SQL> quit
OK,测试通过,开始测试perl能否正确使用ODBC
在使用perl连接ODBC之前要做些准备工作
把ODBC的共享库都复制到/usr/lib目录

# cp /usr/local/unixODBC/lib/libodbc.* /usr/lib


4.PERL脚本测试能否成功:


# vi test.pl


内容如下


#!/usr/bin/perl


use DBI;


$dbh=DBI->connect('dbi:ODBC:123','sa','password');


my $sth=$dbh->prepare("select * from t_ip";


$sth->execute();


while (@data=$sth->fetchrow_array()){


print "$data[0] $data[1] $data[2]\n";


}


保存退出


# perl test.pl


如果可以看到数据库中的记录,就说明可以正常使用ODBC perl了。


既然已经可以实现perl通过ODBC来连接SQLServer了,那么同样可以使用PHP+ODBC+SQLServer

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,