一、安裝pdo_odbc擴展php
參考php官方文檔sql
http://php.net/manual/zh/ref.pdo-odbc.php測試
先安裝unixODBC之類的包,而後編譯pdo_odbc擴展spa
二、安裝Microsoft ODBC Driver for SQL Server on Linux.net
參考微軟官方文檔unix
https://msdn.microsoft.com/en-us/library/hh568454(v=SQL.110).aspxcode
安裝好後用下列代碼測試blog
$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();