CentOS6.8系统ThinkPHP5连接MsSQL数据库。php
ThinkPHP5提供了Mysql、Pgsql、Sqlite和Sqlsrv四种数据库驱动。Window系统下有现成的php_sqlsrv.dll扩展可用,但Linux系统中没有(本人没有找到)。html
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
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
extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/mssql.so"
// 数据库类型 'type' => 'sqlsrv', // 服务器地址 'hostname' => '192.168.1.210', // 数据库名 'database' => 'dbname', // 用户名 'username' => 'sa', // 密码 'password' => '123456', // 端口 'hostport' => '1433',
这种方式在ThinkPHP中是行不通的,在其它应用环境能够。sql
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
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
extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/pdo_dblib.so"
// 数据库类型 'type' => 'dblib', // 服务器地址 'hostname' => '192.168.1.210', // 数据库名 'database' => 'dbname', // 用户名 'username' => 'sa', // 密码 'password' => '123456', // 端口 'hostport' => '1433',
将文件拷贝到 thinkphp/library/think/db
目录。thinkphp
成功。数据库