1.下载pdo_sqlsrv驱动
http://pecl.php.net/package/pdo_sqlsrv
解压.dll到ext目录下
php.ini 里添加
extension=pdo_sqlsrv
2.
在微软官网去下载最新的“Microsoft® ODBC Driver 11 for SQL Server® - Windows”
https://www.microsoft.com/en-us/download/details.aspx?id=36434
3.demo代码
$dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=ysc';
try {
$dbh = new \PDO($dsn, 'sa', '123456');
} catch (\PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sth = $dbh->query("select * from aspnet_Managers");
$result = $sth->fetchAll();
var_dump($result);