首先请到此处下载驱动
配置:
1.将php_sqlsrv.dll 或 php_sqlsrv_ts.dll 放到PHP的扩展目录中(PHP/EXT)。
2.编辑php.ini文件,添加以下扩展:
extension=php_sqlsrv.dll
或
extension=php_sqlsrv_ts.dll
3.重启服务器。
示例:
$dbbase='mydb'; //your db name
$uid='sa'; //your username
$pwd='sa'; //your password
$connectionInfo=array("Database"=>$dbbase,"UID"=>$uid,"PWD"=>$pwd);
$serverName="SQLEXPRESS"; //your serverName
$conn=sqlsrv_connect($serverName,$connectionInfo) or die("Connection could not be established. ");
$strSql = " select * from A ";
$stmt = sqlsrv_query($conn,$strSql);
while(sqlsrv_fetch($stmt)){
echo sqlsrv_get_field($stmt,0);
echo "<br>";
}
sqlsrv_close($conn);