首页 > 系统 > Linux > 正文

CentOS 6.3下给PHP添加mssql扩展模块教程

2019-10-26 18:42:05
字体:
来源:转载
供稿:网友

如果在LINUX系统上需要使用PHP连接Microsoft SQL Server 2005数据库,我们常见的连接数据库方式是使用ODBC方式连接.

FreeTDS为Linux系统提供了TDS协议的开源客户端。由于MSSQL和Sybase使用的恰是TDS协议,所以在Linux中可以用FreeTDS连接MSSQL,下面简绍使用php的db-lib连接Microsoft SQL Server 2005数据库.

LINUX操作系统:   centOS6.3 64bit(安装了系统默认开发包)
APACHE:            httpd-2.4.4
PHP:                  php-5.4.13
freetds:             freetds-0.91

一、关闭iptables和SELINUX

代码如下:
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------

二、同步时间

代码如下:
# ntpdate cn.pool.ntp.org

三、安装APACHE+PHP

传送门://www.jb51.net/article/54969.htm

四、使用FreeTDS启用PHP连接MSSQL

1.下载FreeTds

代码如下:
# su -
# wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz

2.安装FreeTds

代码如下:
# tar -zxvf freetds-stable.tgz
# cd freetds-0.91
# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared --enable-static
# make && make install

3.启用PHP连接MSSQL

方法一:编译php加上freetds路径(初次部署推荐)
代码如下:
# wget http://cn2.php.net/distributions/php-5.4.13.tar.bz2
# tar -jxvf php-5.4.13.tar.bz2
# cd php-5.4.13
# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/lib --with-zlib-dir=/usr/local/lib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-soap --enable-sockets  --enable-xml --enable-mbstring --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-curl=/usr/lib --with-freetype-dir=/usr/include/freetype2/freetype/ --enable-bcmath --enable-calendar --enable-zip --enable-maintainer-zts --with-mssql=/usr/local/freetds
# make && make install

方法二:编译PHP的mssql扩展并加上freetds路径(二次部署推荐)
代码如下:
# wget http://cn2.php.net/distributions/php-5.4.13.tar.bz2
# tar -jxvf php-5.4.13.tar.bz2
# cd php-5.4.13/ext/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模块会默认保存在 /usr/local/php5/lib/php/extensions/no-debug-zts-20090626/ 目录下
 
加载该模块到php
代码如下:

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表