xampp(php5.6)下thinkphp3.2.3连接SQLServer配置

先到 http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx 下载SQLServer驱动

Microsoft Drivers 5.2 for PHP for SQL Server
Microsoft Drivers 4.3 for PHP for SQL Server
4.0、 3.2、 3.1 和 3.0 for PHP for SQL Server 的 Microsoft 驱动程序

不同版本对应不同的PHP版本,具体可以看详细说明,Windows和Linux相关操作系统都有
进入详细页面后,还能看到相关的依赖项目

Supported Operating System

Windows 7, Windows 8, Windows 8.1, Windows Server 2008 R2, Windows Server 2008 Service Pack 2, Windows Vista Service Pack 2

  • Operating Systems supported in this update:
  • Ubuntu 15.04, 16.04
  • RedHat 7
    Requires PHP 7 or 5.x. For information about how to download and install the latest stable binaries, visit 
http://windows.php.net for more detail.Version support for PHP is as follows
  • Version 4.0 supports PHP 7.0+ on Windows and Linux
  • Version 3.2 supports PHP 5.6, 5.5, and 5.4 on Windows
  • Version 3.1 supports PHP 5.5 and 5.4 on Windows
  • Version 3.0 supports PHP 5.4 on Windows

For more detail and for supported operating systems, see  System Requirements (Microsoft Drivers for PHP for SQL Server) . 

An Internet Information Services (IIS) Web server is requiredVersion 4.0 requires  Microsoft ODBC Driver 11 or  Microsoft ODBC Driver 13. Version 4.0 for Linux requires  Microsoft ODBC Driver 13.Versions 3.2 and 3.1 of the driver require Microsoft ODBC Driver 11. You can download the  Microsoft ODBC Driver 11 here.Version 3.0 requires the x86 version of Microsoft SQL Server 2012 Native Client.
我这里选择的是Version3.2,所以要下载Microsoft ODBC Driver 11,并且安装

然后把下载到的SQLSRV32.exe解压缩,就能得到下面的文件

php_pdo_sqlsrv_56_nts.dll
php_pdo_sqlsrv_56_ts.dll
php_sqlsrv_56_nts.dll
php_sqlsrv_56_ts.dll

放到php安装目录下的ext目录下  (ext是php5以后的 都是这个目录)
php配置加载  打开php.ini 搜索  extension 后面添加下面这些

extension=php_pdo_sqlsrv_56_nts.dll
extension=php_pdo_sqlsrv_56_ts.dll
extension=php_sqlsrv_56_nts.dll
extension=php_sqlsrv_56_ts.dll

重启apache就应该能识别了

然后在thinkphp中配置数据库连接
'DB_TYPE' => 'sqlsrv', // 数据库类型    
'DB_HOST' => ' 127.0.0.1', // 服务器地址    
'DB_NAME' => 'test', // 数据库名    
'DB_USER' => 'sa', // 用户名    
'DB_PWD' => '123456', // 密码    
'DB_CHARSET'=> 'utf8', // 字符集
'DB_PORT'=>'1433', // 端口
'DB_PREFIX'=>'', // 数据库表前缀

再写个测试代码
$User = M('Test');
$s = $User->limit(10)->select();
echo json_encode($s);

你可能感兴趣的:(Web开发)