toxic

备忘录

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

安装phpmssql 扩展 如果phpize 找不到命令  需要安装php-devel底包

//进入php的源码目录、MSSQL模块源码目录
# cd /home/wxw/gd/php-5.2.5/ext/mssql/

//生成编译配置文件
# /usr/local/php/bin/phpize

# ./configure --with-php-config=/usr/local/php/bin/php-config --with-mssql=/usr/local/freetds/
# make
# make install

在编译配置的时候可能会遇到找不到FreeTDS的错误:
configure: error: Directory /usr/local/freetds is not a FreeTDS installation directory

 

FreeTDS的软件获取:

      可以在官网上进行下载:http://www.freetds.org/   ,我下载的版本是freetds-0.91,好像是最新版的

FreeTDS的安装:

      1、将下载下来的压缩文件解压到任意目录,进入到解压后的目录中

      2、将身份切换到root身份,开始配置编译环境,

          ./configure  --prefix=/home/joey/work/freetds  --with-tdsver=7.1  --enable-msdblib  --disable-libiconv 

如果以上面的方式编译安装并设置freetds.conf里client charset=utf8   , php连接sqlserver 仍然有乱码的话 ,请删除重新安装

./configure  --prefix=/home/joey/work/freetds  --with-tdsver=7.1 [只指定版本,不用别的参数]

          解释一下各参数的意义:--prefix是FreeTDS的安装路径,可以根据需要随意设置;

                                         --with-tdsver设置FreeTDS的版本,我这里设置了7.1是为了能连接SQL2005,网上有的文档说这里设置成8.0,但是我设置成 8.0后编译出来的居然是5.0的,不知道什么原因,按这样设置成7.1编译出来的FreeTDS的版本就是7.1的;

                                         --enable-msdblib是是否允许Microsoft数据库函数库,这里为允许;

                                         --disable-libiconv这个选项不一定是必须的,FreeTDS会做一次字符集的默认转换,要查找ISO8859-1字符集,这有可能会导致中文乱码;

                                         --host编译器名字,由于我的运行平台是arm平台,所以用到了交叉编译

      3、在配置好了以后,接下来就简单了,就是用make,然后make install ;也可以一步到位,make && make install ;

FreeTDS测试:

      FreeTDS安装好了,接下来就可以查看下FreeTDS状态了;

      运行./tsql  -C ,在安装目录的bin目录下可以找到tsql ,查看终端打印出来信息,可以看到版本号为7.1了:

 

   乱码问题 一定要在freetds的配置文件中 freetds.conf 中 指定client charset = utf8  不然你的php使用utf8编码无论如何转换都是乱码的

 

下面是详细配置

安装freetds到目录/usr/local/freetds:--prefix=/usr/local/freetds 如果不带这个默认好像也是这目录

  对应数据库版本--我的是Microsoft SQL Server 2005 所以我带的是 --with-tdsver=7.2

 

  4.2 Sybase SQL Server < 10 and Microsoft SQL Server 6.5

 

  5.0 Sybase SQL Server >= 10

 

  7.0 Microsoft SQL Server 7.0

 

  7.1 Microsoft SQL Server 2000

 

  7.2 Microsoft SQL Server 2005

 

  3.编辑/usr/local/freetds/etc/freetds.conf

 

  # $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $

 

  #

 

  # This file is installed by FreeTDS if no file by the same

 

  # name is found in the installation directory.

 

  #

 

  # For information about the layout of this file and its settings,

 

  # see the freetds.conf manpage "man freetds.conf".

 

  # Global settings are overridden by those in a database

 

  # server specific section

 

  [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=utf8

 

  # A typical Sybase server

 

  #[egServer50]

 

  # host = symachine.domain.com

 

  # port = 5000

 

  # tds version = 5.0

 

  # A typical Microsoft server

 

  #[egServer70]

 

  # host = ntmachine.domain.com

 

  # port = 1433

 

  # tds version = 7.0

 

  #这个名字程序和命令行用得上,叫什么自己定

 

  [Server2005]

 

  host = 192.168.3.100 #我的SQL Server2005 IP,根据自己改

 

  port = 1433

 

  tds version = 7.2

 

  4.测试连接:

 

  [root@test bin]# ./tsql -S Server2005 -p 1433 -U java -P java -D PublicDB

 

  locale is "zh_CN"

 

  locale charset is "GB2312"

 

  Default database being set to PublicDB

 

  1>

 

  出现这个表示连接成功! 退出:quit 和 exit 都行.

 

  参数说明

 

  -S 配置的服务名

 

  -H 主机名

 

  -p 端口

 

  -U username

 

  -P password

 

  -D database

 

  5.测试查询:

 

  # ./tsql -S Server2005 -p 1433 -U java -P java -D PublicDB

 

  1> select USER_ID,TRUE_NAME from USER_INFO

 

  2> go

 

  可以显示中文没问题!

 

posted on 2013-03-06 14:30  toxic  阅读(2330)  评论(0编辑  收藏  举报