linux下php加载mssql模块
来源:互联网 发布:继电器仿真软件 编辑:程序博客网 时间:2024/06/06 00:17
1、安装配置freetds
wgethttp://mirrors.xmu.edu.cn/ubuntu/archive/pool/main/f/freetds/freetds_0.82.orig.tar.gz
tar zxf freetds_0.82.orig.tar.gz
cd freetds_0.82
./configure --prefix=/usr/local/freetds --with-tdsver=8.0--enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared--enable-staticmake && makeinstall
2、编译php的mssql模块
cd /path/to/php/source进入PHP源码目录
cd ext/mssql进入MSSQL模块源码目录
执行/usr/local/php/bin/phpize 生成编译配置文件
./configure --with-php-config=/usr/local/php/bin/php-config--with-mssql=/usr/local/freetds
make
make install
编译完成生成 mssql.so,修改php.ini,将该模块载入:
extension=”/你的PHP扩展路径/mssql.so”
3、配置mssql
vi freetds.conf
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnosticpurposes
# (setting this to /tmp is insecure on a multi-usersystem)
; 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 yourclient
# is trying to allocate a huge buffer for a TEXTfield.
# Try setting ‘text size' to a more reasonablelimit
text size = 64512
client charset = UTF-8 #加入
#加入
[Server2005]
host = 192.168.x.x
port = 1433
tds version = 7.2
4、测试php连接mssql
try {
$hostname='218.x.x.x';//注意,这里和上面不同,要直接用IP地址或主机名
$port=1433;//端口
$dbname="user";//库名
$username="database";//用户
$pw="passwd";//密码
$dbh= newPDO("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo"Failed to get DB handle: ".$e->getMessage()."n";
exit;
}
echo'connent MSSQL succeed';
$stmt=$dbh->prepare("select * fromz_2010pinjiu_user");
$stmt->execute();
while ($row=$stmt->fetch()) {
print_r($row);
}
unset($dbh); unset($stmt);
关于时间格式问题,如果PHP链接mssql时间格式不正确,解决方法如下:
第一个方法:php文档开头定义ini_set(”mssql.datetimeconvert”,0);
第二个方法:修改php.ini,找到;mssql.datetimeconvert = On ,去掉前面的分号,修改on为off,重启php
关于中文显乱码问题【2014年11月24日补充】
以下转自http://www.linuxidc.com/Linux/2010-12/30815.htm
用自带mssql函数无法设置字符集,setnames不被支持,最后参考了adodb的代码,解决办法是编辑/usr/local/freetds/etc/freetds.conf
在[global]下加上一行
client
另外php.ini 里面mssql.charset
; Specify client character set.
; If empty or not set the client charset from freetds.comf isused
; This is only used when compiled with FreeTDS
当FreeTDS的client charset为空或者没有设置的时候才需要设置这个。曾经错误的将这里设置成utf-8,FreeTDS的client charset也设置成utf8,结果mssql_connect的时候就开始报错了。最终结论,只需要设置FreeTDS的client charset为GBK,然后在php的程序里面iconv('GBK', 'UTF-8//IGNORE', $str);一下就一切正常了。
- (2014-09-30 17:53:31)
- (2014-09-29 10:13:44)
- (2014-09-28 23:42:22)
- (2014-09-28 19:06:34)
- linux下php加载mssql模块
- linux下php加装mssql模块的方法
- Linux下PHP支持MSSQL
- Linux下PHP支持MSSQL(SQL Server2000)
- Linux下PHP支持MSSQL(SQL Server2000)
- linux下添加php的mssql扩展
- php iis 加载 mssql
- php加载mssql扩展
- linux下的模块加载
- linux下的模块加载
- linux下的模块加载
- linux下的模块加载
- LINUX下php连接mssql数据库中文字符乱码问题解决
- Linux下php访问远程mssql server
- linux连接mssql数据库,在Centos7下为PHP安装mssql扩展
- linux下模块加载的一些问题
- linux下的模块加载(转)
- linux 下开机自动加载驱动模块
- 华为数通产品MIB参考
- 将博客搬至CSDN
- linux shell 操作mysql
- linux下php支持snmp
- 用repcache 主备来解决缓存备份和缓存同步问题
- linux下php加载mssql模块
- freetds安装
- phpsnmp监控Linxu服务器
- s9306 mib之entPhysicalTable
- 【菜鸟学Java】14:使用ThreadLocal对Connection进行封装
- eclipse git push 冲突问题解决
- mysql存储过程语法大全
- python 字典
- linux shell读写mysql