广杰博客

  • 首页
  • IT资讯
  • IT运维
  1. 首页
  2. IT运维
  3. 正文

linux下php 加装mssql模块

04/01/2011 1036点热度 0人点赞 0条评论

在linux 下的php连接mssql,就需要安装第三方的freetds了。
1、安装配置freetds
 

  1. wget http://mirrors.xmu.edu.cn/ubuntu/archive/pool/main/f/freetds/freetds_0.82.orig.tar.gz
  2. tar zxf freetds_0.82.orig.tar.gz
  3. cd freetds_0.82
  4. ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 -–enable-msdblib -–enable-dbmfix -–with-gnu-ld -–enable-shared -–enable-static
  5. make && make install

2、编译php的mssql模块
 

  1. cd /path/to/php/source 进入PHP源码目录
  2. cd ext/mssql 进入MSSQL模块源码目录
  3. /usr/local/webserver/php/bin/phpize 生成编译配置文件
  4. ./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-mssql=/usr/local/freetds
  5. make
  6. make install
  7. 编译完成生成 mssql.so,修改php.ini,将该模块载入:
  8. extension=”/path/to/extension/mssql.so”

3、配置mssql
cd /usr/local/freetds/etc
编辑文件:
vi freetds.conf

 

  1. [global]
  2. # TDS protocol version
  3. ; tds version = 4.2
  4. # Whether to write a TDSDUMP file for diagnostic purposes
  5. # (setting this to /tmp is insecure on a multi-user system)
  6. ; dump file = /tmp/freetds.log
  7. ; debug flags = 0xffff
  8. # Command and connection timeouts
  9. ; timeout = 10
  10. ; connect timeout = 10
  11. # If you get out-of-memory errors, it may mean that your client
  12. # is trying to allocate a huge buffer for a TEXT field.
  13. # Try setting ‘text size’ to a more reasonable limit
  14. text size = 64512
  15. client charset = UTF-8 #加入
  16. #加入
  17. [Server2005]
  18. host = 192.168.x.x
  19. port = 1433
  20. tds version = 7.2

4、测试php连接mssql

 

  1. <?php
  2. try {
  3. $hostname='218.x.x.x';//注意,这里和上面不同,要直接用IP地址或主机名
  4. $port=1433;//端口
  5. $dbname="user";//库名
  6. $username="database";//用户
  7. $pw="passwd";//密码
  8. $dbh= new PDO("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
  9. } catch (PDOException $e) {
  10. echo"Failed to get DB handle: ".$e->getMessage() ."n";
  11. exit;
  12. }
  13. echo'connent MSSQL succeed';
  14. $stmt=$dbh->prepare("select * from z_2010pinjiu_user");
  15. $stmt->execute();
  16. while ($row=$stmt->fetch()) {
  17. print_r($row);
  18. }
  19. unset($dbh); unset($stmt);
  20. ?>

 

标签: 暂无
最后更新:01/01/1970

guangjie

这个人很懒,什么都没留下

点赞
下一篇 >

文章评论

您需要 登录 之后才可以评论
最新 热点 随机
最新 热点 随机
Red Hat Enterprise Linux 9 发布,大量组件升级 windows10 家庭版添加hyper-v虚拟机组件 Red Hat Enterprise Linux 8.5 GA 发布 Rocky Linux 8.4 GA正式版发布下载 Rocky Linux 8.3 首个候选版本发布 CentOS 8.3 (2011) ISO镜像下载发布 CentOS Linux 落幕 CentOS Stream 上位 CentOS Linux 7.9 (2009) iso镜像下载 Windows 10 2020年10月更新ISO下载 ubuntu ssh通过密钥登陆服务器
Red Hat Enterprise Linux 9 发布,大量组件升级windows10 家庭版添加hyper-v虚拟机组件
Windows 7进入RC阶段 RTM有望于夏末发布 nginx php上传大文件的设置方法 Windows Server 2012 官方简体中文试用版下载 DevOps工具兵器库 Windows 10 2020年10月更新ISO下载 使用rdesktop实现linux下连接windows远程桌面 ASP.net程序出现“CS0016: 未能写入输出文件”解决方法 超长域名 1到100相加的php程序代码 未与信任 sql server 连接相关联解决
标签聚合
nginx Windows Server 2012下载 Hyper-V php_curl Windows Server 2012 linux redhat springboot
友情链接
  • linux运维
  • 郑州SEO

COPYRIGHT © 2021 gjie.cn. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备07002435号-8