linux下php 加装mssql模块

来源:未知 责任编辑:智问网络 发表时间:2013-10-22 19:23 点击:

作者:coralzd 网址:http://www.freebsdsystem.org/php_mssql
 

在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”  
  9.  

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

 

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

4、测试php连接mssql

 

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

 

本文出自 “崔晓辉的博客” 博客,请务必保留此出处http://coralzd.blog.51cto.com/90341/525106

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Request.ServerVariables 参数大全
    • 执行全文索引时出现权限不足的解决方法
    • 导入excel文件处理流程节点的解决方案
    • 查看sql修改痕迹(SQL Change Tracking on Table)
    • App数据层设计及云存储使用指南
    • PostgreSQL启动过程中的那些事三:加载GUC参数
    • MongoDB安装为Windows服务方法与注意事项
    • Percolator与分布式事务思考(二)
    • 写给MongoDB开发者的50条建议Tip1
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1