I am trying to make a very simple query to a SQL database using PHP, but no matter what I do, it seems it can't pull any proper results. The following is the code I have written:
$loDate = '2013-10-01';
$hiDate = '2015-01-01';
$queryStr = "select TimeCol from dbo.SUBPUMP where TimeCol between " . $loDate . " and " . $hiDate;
$conn = sqlsrv_connect($serverName, $conInfo);
$result = sqlsrv_query($conn, $queryStr);
while ($row = sqlsrv_fetch_array($result)) {
// This never prints.
echo "row:<br>"; var_dump($row); echo "<br><br>";
}
echo "<br><br><br>";
// Prints "conInfo: resource(2) of type (SQL Server Connection)"
echo "conn: "; var_dump($conn); echo "<br><br>";
// Prints "result: resource(3) of type (SQL Server Statement)"
echo "result: "; var_dump($result); echo "<br><br>";
// Prints "row: NULL"
echo "row: "; var_dump($row); echo "<br><br>";
What I am confused on is how it can establish a proper connection to the database.
Since $conn and $result do not print any errors, but yet do not seem to actually fetch any data for me.
So far, my best guess is that since I am attempting to grab the data from a database through a VPN, and thus might only have a tenuous connection, that the sqlsrv_connect() will attempt to try many times to connect to the database until it receives a single good connection. While the sqlsrv_query() will only attempt this once, and thus fails to gather any data.
Does anyone else have any ideas as to what might be going wrong here?