thinkphp mssql.class.php,Linux系统下ThinkPHP5链接MsSQL

案例

CentOS6.8系统ThinkPHP5链接MsSQL数据库。

分析

ThinkPHP5提供了Mysql、Pgsql、Sqlite和Sqlsrv四种数据库驱动。Window系统下有现成的php_sqlsrv.dll扩展可用,但Linux系统中没有(本人没有找到)。

尝试1未成功,写来以备其它用途

安装freetds

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz

tar -zxvf freetds-patched.tar.gz

cd freetds-*

./configure --prefix=/usr/local/freetds --with-tdsver=auto --enable-msdblib --with-gnu-ld --enable-shared --enable-static

make && make install

安装mssql

wget http://cn2.php.net/distributions/php-5.6.22.tar.gz

tar -zxvf php-5.6.22.tar.gz

cd php-*/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

修改php.ini,添加如下配置(路径请根据环境不同而定)

extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/mssql.so"

修改ThinkPHP5配置文件database.php

// 数据库类型

'type' => 'sqlsrv',

// 服务器地址

'hostname' => '192.168.1.210',

// 数据库名

'database' => 'dbname',

// 用户名

'username' => 'sa',

// 密码

'password' => '123456',

// 端口

'hostport' => '1433',

测试

这种方式在ThinkPHP中是行不通的,在其它应用环境可以。

尝试2成功

安装freetds

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz

tar -zxvf freetds-patched.tar.gz

cd freetds-*

./configure --prefix=/usr/local/freetds --with-tdsver=auto --enable-msdblib --with-gnu-ld --enable-shared --enable-static

make && make install

安装pdo_dblib

wget http://cn2.php.net/distributions/php-5.6.22.tar.gz

tar -zxvf php-5.6.22.tar.gz

cd php-*/ext/pdo_dblib

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-dblib=/usr/local/freetds

make && make install

修改php.ini,添加如下配置(路径请根据环境不同而定)

extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/pdo_dblib.so"

修改ThinkPHP5配置文件database.php

// 数据库类型

'type' => 'dblib',

// 服务器地址

'hostname' => '192.168.1.210',

// 数据库名

'database' => 'dbname',

// 用户名

'username' => 'sa',

// 密码

'password' => '123456',

// 端口

'hostport' => '1433',

下载ThinkPHP数据库驱动Dblib文件

将文件拷贝到 thinkphp/library/think/db 目录。

测试

成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值