linux+php连接mssql

本文介绍如何在Linux环境下使用PHP连接Microsoft SQL Server (MSSQL),包括配置Freetds模块、设置环境变量及路径,以及通过示例代码验证连接是否成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

因为环境需要,linux+php连接mssql
安装加载freetds模块过程省略网上很多

在/etc/profile
中加入export PATH="$PATH:/usr/local/freetds/bin"
#echo "/usr/local/freetds/lib" >> /etc/ld.so.conf
source /etc/profile
#ldconfig
再配置freetds
/usr/local/freetds/etc
[root@xafcbackup ~]# cat /usr/local/freetds/etc/freetds.conf 
[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

       host = 51.102.121.217
       port = 1433
       tds version = 8.0
       client charset = GBK
[root@xafcbackup etc]# cat /data/caijishuju/t.php 
<?php 
$conn=mssql_connect("51.102.121.217","sa", xaj!@34);
      //test
          if($conn)
      {
      echo "ok";
      } else

          {
          echo "no";
          }
?>
程序配置文件连接的是定义的名称而不是ip否则不能连接!
参考http://coralzd.blog.51cto.com/90341/525106


本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/664505
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值