<?php

$serverName = "LASUCA2K8\CBM"; 
$uid = "cbm";
$pwd = "ascbm2k";
$connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd,'ReturnDatesAsStrings'=> true, "CharacterSet" => 'utf-8', "Database"=>"SugarCaneScale" );

/* Connect using SQL Server Authentication. */  
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
if( $conn === false )  
{  
	echo "Unable to connect.</br>";  
	die( print_r( sqlsrv_errors(), true));  
} 

$sql = "SELECT TOP 20 LoadId_Pk, CropDay, TractId_Fk, TareIN, GrossWt, Tons, FarmerId_Fk, DateOut, SplitPercent
		FROM LoadData 
		WHERE FarmerId_Fk
		LIKE 32002
		ORDER by LoadId_Pk DESC";
		
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
	echo $row['LoadId_Pk'].", ".$row['TareIN'].", ".$row['GrossWt'].", ".$row['Tons'].", ".$row['GrossWt'].", ".$row['FarmerId_Fk']."<br />";
} 

/* Free statement and connection resources. */  
sqlsrv_free_stmt( $stmt);  
sqlsrv_close( $conn);  
?>