在 PHP 中连接 SQL SERVER 2012
<?php
$serverName = "服务器"; $connectionInfo = array( "数据库"=>"base", "UID"=>"ex", "PWD"=>"******");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
;
if( $conn ) {
echo "连接已建立。<br />";
}else{
echo "连接无法建立。<br />";
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT name FROM [base].[dbo].[table]";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query( $conn, $sql , $params, $options );
$row_count = sqlsrv_num_rows( $stmt );
if ($row_count === false)
echo "获取数据时出错。";
else
echo "好";
while( $row = sqlsrv_fetch_array( $stmt) ) {
print json_encode($row);
}
sqlsrv_close($conn);
?>