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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章