linux php 连接sql server2000_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > linux php 连接sql server2000

linux php 连接sql server2000

 2014/8/17 23:37:57  hw1287789687  程序员俱乐部  我要评论(0)
  • 摘要:说明:Linux服务器系统:CentOS5.5Web环境:LAMP或者LNMPWindows服务器系统:WindowsServer2003Windows服务器IP地址:192.168.21.134数据库环境:SQLServer2000数据库数据库账号:sa数据库密码:123456实现目的:Linux服务器中的php程序能够连接到Windows服务器中的SQLServer2000数据库具体步骤:一、在Linux服务器中安装freetds1
  • 标签:Server Linux PHP 连接 SQL

说明:

Linux服务器系统:CentOS 5.5

Web环境:LAMP或者LNMP

Windows服务器系统:Windows Server 2003

Windows服务器IP地址:192.168.21.134

数据库环境:SQL Server 2000数据库

数据库账号:sa

数据库密码:123456

实现目的:Linux服务器中的php程序能够连接到Windows服务器中的SQL Server 2000数据库

具体步骤:

一、在Linux服务器中安装freetds

1、安装编译工具及驱动程序

yum install make apr* autoconf automake gcc gcc-c++ wget

2、安装unixODBC驱动程序

yum -y install unixODBC unixODBC-devel

3、安装freetds

cd /usr/local/src

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz #下载

gunzip freetds-stable.tgz #解压

tar -xvf freetds-stable.tar

cd freetds-0.91

./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --with-unixodbc=/usr --enable-msdblib #配置

make #编译

make install #安装

4、配置freetds

cp /usr/local/freetds/etc/freetds.conf /usr/local/freetds/etc/freetds.confbak #备份原有文件

vi /usr/local/freetds/etc/freetds.conf #在最后位置修改编辑以下内容

系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链

[192.168.21.134]
host = 192.168.21.134 #SQL Server 2000服务器地址
port = 1433 #SQL Server 2000数据库端口
tds version = 8.0 #8.0代表数据库版本为SQL Server 2000
client charset = UTF-8 #设置字符集

5、测试freetds

/usr/local/freetds/bin/tsql -S 192.168.21.134 -U sa #测试,提示输入数据库密码,出现下面界面,配置成功

cd /usr/local/freetds/bin

./tsql -S 192.168.21.134 -p 1433 -U sa -P 123456 -D master #测试,出现下面界面,配置成功

二、配置Linux php连接SQL Server 2000数据库

1、php是用yum命令在线安装

yum install php-mssql #安装php-mssql扩展,如果提示没有此安装包,请先配置第三方yum源

wget http://www.atomicorp.com/installers/atomic #下载

sh ./atomic #安装

[root@huangwei bin]# sh ./atomic
ln: "/etc/system-release" 与"/etc/fedora-release" 为同一文件

Atomic Free Unsupported Archive installer, version 2.0.12

BY INSTALLING THIS SOFTWARE AND BY USING ANY AND ALL SOFTWARE
PROVIDED BY ATOMICORP LIMITED YOU ACKNOWLEDGE AND AGREE:

THIS SOFTWARE AND ALL SOFTWARE PROVIDED IN THIS REPOSITORY IS
PROVIDED BY ATOMICORP LIMITED AS IS, IS UNSUPPORTED AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ATOMICORP LIMITED, THE
COPYRIGHT OWNER OR ANY CONTRIBUTOR TO ANY AND ALL SOFTWARE PROVIDED
BY OR PUBLISHED IN THIS REPOSITORY BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

====================================================================
THIS SOFTWARE IS UNSUPPORTED.? IF YOU REQUIRE SUPPORTED SOFWARE
PLEASE SEE THE URL BELOW TO PURCHASE A NUCLEUS LICENSE AND DO NOT
PROCEED WITH INSTALLING THIS PACKAGE.
====================================================================

For supported software packages please purchase a Nucleus license:
https://www.atomicorp.com/products/nucleus.html
All atomic repository rpms are UNSUPPORTED.
Do you agree to these terms? (yes/no) [Default: yes] yes

Configuring the [atomic] yum archive for this system

Installing the Atomic GPG key: OK
Downloading atomic-release-1.0-19.fc20.art.noarch.rpm:
OK



The Atomic Rocket Turtle archive has now been installed and configured for your system
The following channels are available:
? atomic????????? - [ACTIVATED] - contains the stable tree of ART packages
? atomic-testing? - [DISABLED]? - contains the testing tree of ART packages
? atomic-bleeding - [DISABLED]? - contains the development tree of ART packages

?

yum install php-mssql #再次执行

2、php是用源码编译安装

cd /usr/local/src/php-5.3.15/ext/mssql #进入php源码包的ext下mssql目录

/usr/local/php5/bin/phpize

./configure --with-php-config=/usr/local/php5/bin/php-config --with-mssql=/usr/local/freetds #配置

注意:--with-mssql=/usr/local/freetds #是指freetds的安装路径

make #编译

make install #安装

vi /usr/local/php5/etc/php.ini #编辑,在最后位置添加下面一行

extension = "mssql.so"

:wq! #保存退出

3、重启LAMP或者LNMP

service httpd restart #重启apache

service php-fpm restart #重启php-fpm

三、测试php连接SQL Server 2000数据库

进入php程序目录,新建一个测试文件

cd /usr/local/nginx/html #请改为自己的网站目录

vi sql.php #添加以下内容

<?php

$mssql=mssql_connect("192.168.21.134","sa","123456");

if ($mssql) {

echo "Connent Mssql Succeed";

}

else {

echo "connent Mssql Error!";

}

?>

:wq! #保存退出

注意:这里的192.168.21.134必须要和/usr/local/freetds/etc/freetds.conf中的[192.168.21.134]完全一样

在浏览器中打开,出现下面的界面,连接成功

可以在新建一个文件

vi index.php

<?php

phpinfo();

?>

在浏览器中打开,能找到mssql,说明配置成功,如下图所示

至此,Linux下php连接SQL Server 2000数据库配置完成

?

  • 相关文章
发表评论
用户名: 匿名