下载SQLSRV510 :https://go.microsoft.com/fwlink/?linkid=2199011
解压后,将红箭头指向的拷到php的ext目录下
然后在php.ini 里加上
extension=php_pdo_sqlsrv_74_ts_x64.dll
extension=php_sqlsrv_74_ts_x64.dll
然后写个php 测试文件代码如下
<?php
ini_set('display_errors','On');
ini_set("error_reporting",E_ALL);
try {
$dsn = 'sqlsrv:Server=192.168.1.190;Database=Test_DB;TrustServerCertificate=true';
$options = array();
$dbh = new PDO($dsn, 'dbedit', 'test111', $options);
$dbh->query("SET NAMES utf8");
var_dump($dbh->query('select @@version')->fetchColumn());
}
catch (PDOException $e)
{
exit("connect failed." . $e->getMessage());
}
然后报下面错
SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server
然后下载ODBC驱动
https://go.microsoft.com/fwlink/?linkid=2202930
安装好以后,运行测试代码又报
证书链由不受信任的颁发机构颁发
然后在PHP代码里加上
;TrustServerCertificate=true
问题得到解决,安装完成!