Linux 下 PHP 5.2.x 连接 SQL Server 数据库 FreeTDS 配置笔记
浏览:10083次 出处信息
1、编译安装FreeTDS
mkdir -p /data0/software/
cd /data0/software/
wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar zxvf freetds-stable.tgz
cd freetds-0.82/
./configure --prefix=/usr/local/webserver/freetds --with-tdsver=8.0 --enable-msdblib
make && make install
cd ../
echo "/usr/local/webserver/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
ln -s /usr/local/webserver/freetds/lib/libsybdb.so.5.0.0 /usr/local/webserver/freetds/lib/libsybdb.so.4
/sbin/ldconfig
rm -f /usr/local/webserver/freetds/etc/freetds.conf
vi /usr/local/webserver/freetds/etc/freetds.conf
cd /data0/software/
wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar zxvf freetds-stable.tgz
cd freetds-0.82/
./configure --prefix=/usr/local/webserver/freetds --with-tdsver=8.0 --enable-msdblib
make && make install
cd ../
echo "/usr/local/webserver/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
ln -s /usr/local/webserver/freetds/lib/libsybdb.so.5.0.0 /usr/local/webserver/freetds/lib/libsybdb.so.4
/sbin/ldconfig
rm -f /usr/local/webserver/freetds/etc/freetds.conf
vi /usr/local/webserver/freetds/etc/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
host = mssql.yourdomain.com
port = 1433
tds version = 8.0
client charset = UTF-8
# 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
host = mssql.yourdomain.com
port = 1433
tds version = 8.0
client charset = UTF-8
2、编译安装PHP自带MSSQL扩展
进入本地已存在的php-5.2.XX源码包目录:
cd /data0/software/php-5.2.XX/ext/mssql/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-mssql=/usr/local/webserver/freetds/
make && make install
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-mssql=/usr/local/webserver/freetds/
make && make install
3、在php.ini配置文件中增加mssql.so
vi /usr/local/webserver/php/etc/php.ini
增加一行:
引用
extension = "mssql.so"
4、重启PHP FastCGI
/usr/local/webserver/php/sbin/php-fpm restart
5、测试文件(test_mssql.php):
- <?php
- header("Content-type: text/html; charset=utf-8");
- $msdb=mssql_connect("mssql.yourdomain.com:1433","username","password");
- if (!$msdb) {
- echo "connect sqlserver error";
- exit;
- }
- mssql_select_db("database_name",$msdb);
- $result = mssql_query("SELECT top 5 * FROM table", $msdb);
- while($row = mssql_fetch_array($result)) {
- var_dump($row);
- }
- mssql_free_result($result);
- ?>
建议继续学习:
- 配置Nginx+uwsgi更方便地部署python应用 (阅读:105382)
- nginx的配置文件 (阅读:8793)
- Emacs安装配置 (阅读:7292)
- 如何查看Linux 硬件配置信息 (阅读:5846)
- Centos yum 安装nginx+PHP-FPM+eAccelerator+mysql (阅读:5597)
- Apache2中俩种设置PHP的异同 (阅读:5273)
- Linux(Ubuntu 10.04)上安装配置apache+php+mysql+phpmyadmin (阅读:4990)
- 在FreeNAS/BSD搭建基于Nginx+FastCGI+MySQL+PHP的WebServer (阅读:4736)
- 在Mac OS X中运行Apache + PHP + MySQL (阅读:4342)
- apache+mod_wsgi+django在windows下的部署 (阅读:4124)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:Linux下获取IO压力数据
后一篇:AWStats是一个基于Perl的WEB日志分析工具。 >>
文章信息
- 作者:张宴 来源: 回忆未来
- 标签: FreeTDS 配置
- 发布时间:2010-06-27 22:24:52
建议继续学习
- 配置Nginx+uwsgi更方便地部署python应用
- nginx的配置文件
- Emacs安装配置
- 如何查看Linux 硬件配置信息
- Centos yum 安装nginx+PHP-FPM+eAccelerator+mysql
- Apache2中俩种设置PHP的异同
- Linux(Ubuntu 10.04)上安装配置apache+php+mysql+phpmyadmin
- 在FreeNAS/BSD搭建基于Nginx+FastCGI+MySQL+PHP的WebServer
- 在Mac OS X中运行Apache + PHP + MySQL
- apache+mod_wsgi+django在windows下的部署
近3天十大热文
- [66] Oracle MTS模式下 进程地址与会话信
- [65] Go Reflect 性能
- [64] 如何拿下简短的域名
- [60] android 开发入门
- [59] 图书馆的世界纪录
- [59] 【社会化设计】自我(self)部分――欢迎区
- [58] IOS安全–浅谈关于IOS加固的几种方法
- [54] 视觉调整-设计师 vs. 逻辑
- [48] 读书笔记-壹百度:百度十年千倍的29条法则
- [47] 界面设计速成