<?php $serverName = "(local)"; $uid = 'xxxx'; $pwd = 'xxxx'; $connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd, "Database"=>"AdventureWorks"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "无法连接数据库."; die( print_r( sqlsrv_errors(), true)); } $tsql = "SELECT CONVERT(varchar(32), SUSER_SNAME())"; $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false ) { echo "查询错误."; die( print_r( sqlsrv_errors(), true)); } $row = sqlsrv_fetch_array($stmt); echo "登录的用户: ".$row[0]; sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); ?>
希望本文所述对大家的php程序设计有所帮助。