Linux PHP Connection SQL Server 2000 database configuration method _linux

Source: Internet
Author: User
Tags fpm install php mssql

Description

Linux Server system: CentOS 5.5

Web environment: Lamp or LNMP

Windows Server System: Windows Server 2003

Windows Server IP Address: 192.168.21.134

Database environment: SQL Server 2000 database

Database account: SA

Database Password: 123456

Implementation purpose: PHP programs in Linux servers can connect to SQL Server 2000 databases in Windows Server

Specific steps:

First, install the FreeTDS on the Linux server

1, install the compilation tool and the driver program

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

2. Install UNIXODBC Driver

Yum-y Install UNIXODBC Unixodbc-devel

3. Installation 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. Configure FreeTDS

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

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

System Yun-wei www.osyunwei.com warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original chain

[192.168.21.134]
Host = 192.168.21.134 #SQL Server 2000 servers address
Port = 1433 #SQL Server 2000 database ports
TDS Version = 8.0 #8.0 represents the database version of SQL Server 2000
Client charset = UTF-8 #设置字符集

5. Test FreeTDS

/usr/local/freetds/bin/tsql-s 192.168.21.134-u sa #测试, prompted to enter the database password, the following interface appears, the configuration was successful

Cd/usr/local/freetds/bin

./tsql-s 192.168.21.134-p 1433-u sa-p 123456-d Master #测试, the following interface appears, configured successfully

Configure the Linux PHP connection SQL Server 2000 database

1, PHP is installed with the Yum command online

Yum install php-mssql #安装php-mssql extension, Configure a third-party yum source if you are not prompted for this installation package

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

Sh./atomic #安装

Yum install php-mssql #再次执行

2, PHP is compiled with the source code installation

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 #配置

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

Make #编译

Make install #安装

Vi/usr/local/php5/etc/php.ini #编辑, add the following line at the last position

Extension = "mssql.so"

: wq! #保存退出

3. Restart lamp or LNMP

Service httpd restart #重启apache

Service php-fpm Restart #重启php-fpm

Third, test PHP connection SQL Server 2000 database

Enter the PHP program directory and create a new test file

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! #保存退出

Note: The 192.168.21.134 here must be exactly the same as [192.168.21.134] in/usr/local/freetds/etc/freetds.conf.

Open in Browser, the following interface appears, the connection is successful

You can create a new file

VI index.php

<?php

Phpinfo ();

?>

Open in the browser, can find MSSQL, description of the success of the configuration, as shown in the following figure

At this point, Linux PHP connects SQL Server 2000 database configuration complete

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.