基于Linux下PHP连接SQL Server的FreeTDS配置_PHP教程
程序员文章站
2022-03-15 20:03:21
...
CentOS 5.4 Linux 下的 PHP(FastCGI) 需要连接相关部门的SQL Server 2000数据库,配置了扩展FreeTDS扩展。
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
输入以下内容:
引用
- [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
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
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);
- ?>
上一篇: js基础提升学习之基本数据类型
下一篇: win10电脑睡眠后自动关机
推荐阅读
-
Linux下php连接SQLServer 2000数据库的配置方法
-
PHP连接SQL Server的方法分析【基于thinkPHP5.1框架】
-
Linux系统下PHP-FPM的安装和配置教程
-
wxzh001,进来看关于APACHE+PHP+MYSQL+SSL的LINUX下安装配置(转自奥索)_PHP教程
-
Linux下PHP连接MSSQLServer的办法_PHP教程
-
PHP在Linux下连接MSSQLServer的配置方法简述(二、FreeTDS库)_PHP教程
-
PHP在Linux下连接MSSQLServer的配置方法简述(一、Sybase库)_PHP教程
-
PHP教程:Linux下PHP服务器的安装与配置
-
Linux下php连接SQLServer 2000数据库的配置方法
-
在Navicat premium上创建的SQL Server数据库,实现用PHP连接(即php连接微软MSSQL),navicatpremium_PHP教程