1.安装对应以下扩展:
php_odbc.dll
php_pdo_odbc.dll
php_sqlsrv_73_nts_x64.dll
php_pdo_sqlsrv_73_nts_x64.dll
2.安装odbc驱动
3.编写连接数据库脚本:
try {
$database=iconv("utf-8","gb2312//IGNORE",$database);
$sqlsrv = new PDO("sqlsrv:Server=$host,1433;Database=".$database,$user,$pass);
$sql="select clientid,name from client where clientid>100 and clientid <200";
$res=$sqlsrv->query($sql)->fetchAll(PDO::FETCH_ASSOC);
var_dump($res);
}catch (PDOException$e) {
exit($e->getMessage(). "\n");
}