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
成功。數據庫