by unWing » 25. March 2012 06:41
I've followed your guide correctly and got connected to the server, but when i try to retrieve the records nothing happen. it return blank. Here is the code Im trying to test.
<?php
$serverName = "MyServer";
$connectionInfo = array( "Database"=>"MyDBS");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn === false )
{
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
else
{
echo "Connection established.</br>";
}
$tsql = "SELECT * FROM Personnel";
$stmt = sqlsrv_query($conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
if (sqlsrv_num_rows($stmt) > 0 ) //not working, returned blank
{
echo "<table cellpadding=10 border=1>";
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";//instead of numeric use the field name $row["CompanyNum"]
echo "<td>".$row[1]."</td>";//$row["EmployeeNum"]
echo "</tr>";
}
echo "</table>";
}
else {
echo "No rows found!";
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>