linux php pdo mssql,Linux php5.3 安装Mssql 2008支持

本文详细介绍了在Linux系统中安装Freetds、PHP5.3的mssql扩展以及配置freetds.conf的过程,以实现与MSSQL2008服务器的连接。通过编译安装Freetds和PHP扩展,并修改配置文件,最终成功建立连接并进行了测试。
摘要由CSDN通过智能技术生成

1.下载freetds 并安装

wget ftp://ftp.freetds.org/pub/freetds/current/freetds-current.tar.gz

tar -zvxf freetds-current.tar.gz

cd freetds-dev.0.99.479

./configure --prefix=/usr/local/freetds --with-tdsver=7.2 --enable-msdblib --with-gnu-ld --enable-shared --enable-static

make && make install

wget ftp://ftp.freetds.org/pub/freetds/current/freetds-current.tar.gz

tar -zvxf freetds-current.tar.gz

cd freetds-dev.0.99.479

./configure --prefix=/usr/local/freetds --with-tdsver=7.2 --enable-msdblib --with-gnu-ld --enable-shared --enable-static

make && make install

2安装php5.3 mssql扩展

wget http://cn2.php.net/distributions/php-5.3.29.tar.gz

tar -zvxf php-5.3.29.tar.gz

cd php-5.3.29/ext/mssql

/www/wdlinux/nginx_php-5.3.29/bin/phpize //生成编译配置文件

./configure --with-php-config=/www/wdlinux/nginx_php-5.3.29/bin/php-config --with-mssql=/usr/local/freetds

make

make install

wget http://cn2.php.net/distributions/php-5.3.29.tar.gz

tar -zvxf php-5.3.29.tar.gz

cd php-5.3.29/ext/mssql

/www/wdlinux/nginx_php-5.3.29/bin/phpize //生成编译配置文件

./configure --with-php-config=/www/wdlinux/nginx_php-5.3.29/bin/php-config --with-mssql=/usr/local/freetds

make

make install

编译完成生成 mssql.so,修改php.ini,将该模块载入:

extension=/path/to/extension/mssql.so

extension=/path/to/extension/mssql.so

3.编辑freetds.conf /usr/local/freetds/etc下

# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $

#

# This file is installed by FreeTDS if no file by the same

# name is found in the installation directory.

#

# For information about the layout of this file and its settings,

# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database

# server specific section

[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

# A typical Sybase server

[egServer50]

host = symachine.domain.com

port = 5000

tds version = 5.0

# A typical Microsoft server

[egServer70]

host = ntmachine.domain.com

port = 1433

tds version = 7.0

[sql2008]

host = ntmachine.domain.com

port = 1433

tds version = 7.2

# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $

#

# This file is installed by FreeTDS if no file by the same

# name is found in the installation directory.

#

# For information about the layout of this file and its settings,

# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database

# server specific section

[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

# A typical Sybase server

[egServer50]

host = symachine.domain.com

port = 5000

tds version = 5.0

# A typical Microsoft server

[egServer70]

host = ntmachine.domain.com

port = 1433

tds version = 7.0

[sql2008]

host = ntmachine.domain.com

port = 1433

tds version = 7.2

5.测试

/usr/local/freetds/bin/tsql -S sql-server-2000 -U sa -P test

/usr/local/freetds/bin/tsql -S sql-server-2000 -U sa -P test

出现

locale is "zh_CN.UTF-8"

locale charset is "UTF-8"

using default charset "UTF-8"

1>

locale is "zh_CN.UTF-8"

locale charset is "UTF-8"

using default charset "UTF-8"

1>

6.成功

7.程序使用

< ?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 xmspace_net");

$stmt->execute();

while ($row=$stmt->fetch()) {

print_r($row);

}

unset($dbh); unset($stmt);

?>

< ?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 xmspace_net");

$stmt->execute();

while ($row=$stmt->fetch()) {

print_r($row);

}

unset($dbh); unset($stmt);

?>

测试是否能正常连接mssql2008

无限星辰 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Linux php5.3 安装Mssql 2008支持!

springboot034基于Springboot+Vue在线商城系统设计与开发毕业源码案例设计 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值