<?php
$serverName = "208.109.217.124\SQLEXPRESS";
$connectionInfo = array( "Database"=>"ATTENDANCE", "UID"=>"aadhocc", "PWD"=>"aadhocc");
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if( $conn === false ) {
    die( print_r( sqlsrv_errors(), true));
}

$sql = "SELECT * FROM [Devices] as A LEFT JOIN [DeviceLogs] as B  ON  A.DeviceId=B.DeviceId WHERE B.sync_status=0 and  SerialNumber=".$serialNumber." and sync_status=0";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_object( $stmt) ) {
      echo $row->UserId.", ".$row->deviceId."<br />";
}

//sqlsrv_free_stmt( $stmt);
?>