温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

linux下php如何加装mssql模块

发布时间:2022-05-06 10:24:53 来源:亿速云 阅读:169 作者:iii 栏目:大数据

这篇文章主要讲解了“linux下php如何加装mssql模块”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“linux下php如何加装mssql模块”吧!

1、安装配置freetds

复制代码 代码如下:

wget http://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-static
make && make install

2、编译php的mssql模块

复制代码 代码如下:

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

3、配置mssql

复制代码 代码如下:

cd /usr/local/freetds/etc
编辑文件:
vi 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
client charset = utf-8 #加入
#加入
[server2005]
host = 192.168.x.x
port = 1433
tds version = 7.2

4、测试php连接mssql

复制代码 代码如下:

<?php
try {
$hostname='218.x.x.x';//注意,这里和上面不同,要直接用ip地址或主机名
$port=1433;//端口
$dbname="user";//库名
$username="database";//用户
$pw="passwd";//密码
$dbh= new pdo("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 * from z_2010pinjiu_user");
$stmt->execute();
while ($row=$stmt->fetch()) {
print_r($row);
}
unset($dbh); unset($stmt);
?>

感谢各位的阅读,以上就是“linux下php如何加装mssql模块”的内容了,经过本文的学习后,相信大家对linux下php如何加装mssql模块这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI