1、安装pdo_odbc扩展
参考php官方文档
http://php.net/manual/zh/ref.pdo-odbc.php
先安装unixODBC之类的包,然后编译pdo_odbc扩展
2、安装Microsoft ODBC Driver for SQL Server on Linux
参考微软官方文档
https://msdn.microsoft.com/en-us/library/hh568454(v=SQL.110).aspx
安装好后用下列代码测试
$obj = new \PDO("odbc:Driver={ODBC Driver 13 for Sql Server};Server=111.111.111.111;Database=dbname;","dbuser","pwd");
$sql = 'SELECT top 1 * from table';
foreach ($obj->query($sql) as $row) {
var_dump($row);
}
exit();