Chinaunix首页 | 论坛 | 博客
  • 博客访问: 400923
  • 博文数量: 147
  • 博客积分: 5400
  • 博客等级: 大校
  • 技术积分: 1380
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-12 20:29
文章分类

全部博文(147)

文章存档

2013年(1)

2012年(44)

2011年(5)

2010年(4)

2009年(22)

2008年(71)

分类: 系统运维

2009-11-18 16:09:00

操作系统:freebsd 7.2 所有软件包均通过ports安装
php版本:5.2.11
 
安装mssql模块:
  cd /usr/ports
  make search name=php5-mssql
  cd /usr/ports/databases/php5-mssql
  make install clean
注:在安装mssql模块的过程中,由于包的依赖关系,freetds也会被安装。
   安装完后检查一下在/usr/local/etc/php/extensions.ini是否有extension=mssql.so这条纪录
   默认会自动添加的
 
配置freetds:
 cp /usr/local/etc/freetds.conf.dist /usr/local/etc/freetds.conf
 chmod +w /usr/local/etc/freetds.conf
 以下为我自己的freetds.conf的内容
 [global]
        # TDS protocol version
        tds version = 4.2
;       initial block size = 512
        # uses some fixes required for some bugged MSSQL 7.0 server that
        # return invalid data to big endian clients
        # NOTE TDS version 7.0 or 8.0 should be used instead
;       swap broken dates = no
;       swap broken money = no
        # 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.
        # (Microsoft servers sometimes pretend TEXT columns are
        # 4 GB wide!)   If you have this problem, try setting
        # 'text size' to a more reasonable limit
        text size = 64512

[sqlserver]
        host = 192.168.212.1
        port = 1433
        tds version = 4.2 (注,此版本在连接SQL 2005 可能需要和GLOBAL中的tds version 一致)
 
此时已经配置完成
 
 
 
检查一下是否成功配置:
 
在php中建立数据库连接

$link=mssql_connect("sqlserver",$your_username,$your_password) or die (“can’t Connect to Database”);
浏览器中运行上面脚本, 如果你得到一个link号,你已经配置好了,如果出现Call to undefined function: mssql_connect() 那说明仔细看上面的安装配置过程看你哪一步没有对。

注意:sqlserver名称是在/usr/local//etc/freetds.conf中定义的sqlserver字段,如果你写的IP地址,就是IP地址
 
调试

如果出现不能连接,请在freetds配置文件中找到;dump file = /tmp/freetds.log这一行,注释掉前面的分号,再执行一下测试脚本,察看/tmp/freetds.log文件,它可以告诉你很多出错的信息帮助你排除问题
echo $link;
 
阅读(1104) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~