1: /* Specify the server and connection string attributes. */
2: $serverName = "(local)";
3: $connectionInfo = array( "UID"=>"sa",
4: "PWD"=>"password",
5: "Database"=>"Northwind");
6:
7: /* Connect using SQL Server Authentication. */
8: $conn = sqlsrv_connect( $serverName, $connectionInfo);
9: if( $conn === false )
10: { 11: echo "Unable to connect.</br>";
12: die( print_r( sqlsrv_errors(), true));
13: }
14:
15: $tsql = "SELECT * FROM Customers";
16: $stmt = sqlsrv_query( $conn, $tsql);
17: if( $stmt === false )
18: { 19: echo "Error in executing query.</br>";
20: die( print_r( sqlsrv_errors(), true));
21: }
22: $data = "[";
23: while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
24: { 25: $data = $data . json_encode($row) . ", ";
26: }
27: $data = $data . "]";
28: echo $data;
29:
30: /* Free statement and connection resources. */
31: sqlsrv_free_stmt( $stmt);
32: sqlsrv_close( $conn);