1、下载
https://www.microsoft.com/en-us/download/confirmation.aspx?id=20098
先看下自己的php版本号,然后放置对应的dll文件 E:\www\dingshang\shell>php -v
PHP 5.6.27 (cli) (built: Oct 14 2016 10:22:59)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
我这里是5.6的,然后把上面的都下载下来,找到对应的文件 注意选用pdo的
2、配置: ; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension
extension=php_pdo_sqlsrv_56_nts.dll
;extension=php_bz2.dll
extension=php_curl.dll
extension=php_imagick.dll
;extension=php_fileinfo.dll
3、连接方法 host-ip: 10.4.2.50
host-name: mssqlhost.mydomain.org
mssql-server-name: foo-sql
mssql-instance-name: MSSQLSERVER
database-name: mydb
$dbh = new PDO("sqlsrv:Server=foo-sql,1433;Database=mydb", $user , $pass);
?>
4、提示错误,少了 ODBC Driver 11 for SQL Server for x86 Failed to get DB handle: SQLSTATE[IMSSP]: This extension requires the Microsoft
ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the followi
ng URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsof
t.com/fwlink/?LinkId=163712
直接下载安装就可以了
参考资料