all,
i have been lurking on stackoverflow for a few years now, always able to find the help needed to resolve the issue at hand. however, this time, i needed to create my first question as i was unable to find questions that hit on the same issue i am encountering.
i have been stumped for over a week and am getting into hot water at work because i already blew my estimated date. i put myself at your mercy in the hopes that you may help me with my coding headache.
i am able to return data from executing a stored procedure through PHP on a SQL 2008 server on a VM (running windows 2008 r2) where i pass in one parameter.
that parameter has a total of eleven (11) choices. whenever i pass in one (1) of those choices, expected data is returned.
however, whenever i use any of the other choices, no data is returned (and with my current code, no errors are returned either).
there are 11 choices of $application_selected to pass into the stored procedure and only one (1) of those choices returns data. none of the others return data or errors.
here is my entire code:
<!DOCTYPE html>
<html>
<head>
<title>data</title>
</head>
<body>
<?php
////////////////////////////////////////////////////////////////////////////
//connection information
$servername = "192.168.1.104";
$username = "sa";
$password = "*";
$database = "*";
$connection_info = array( "Database"=>$database, "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect( $servername, $connection_info);
if($conn===FALSE) die( print_r( sqlsrv_errors(), true));
else echo "<font color=\"blue\">DB Connected.</font><br>";
/////////////////////////////////////////////////////////////////////////////
$application_selected = "param1";
$sql_cmd = "EXECUTE GetApprover '$application_selected'";
$execute_this = sqlsrv_prepare($conn, $sql_cmd);
$application_proc = sqlsrv_execute($execute_this);
if($application_proc===FALSE) die( print_r( sqlsrv_errors(), true)); //execute failed; die and display errors
else echo "<font color=\"blue\">DB data retrieved.</font><br><br>";
$row_apps = "";
$count = 0;
echo "<font color=\"blue\">Attempting data output via loop</font><br><br>";
/////////////////////////////////////////////////////////////////////////////
// output data
//echo var_dump($execute_this)."<br><br>";
echo "<font color=\"blue\">Application selected = </font>\"".$application_selected."<font color=\"blue\">\" - data pulled ▼</font><br><br>";
while(($row_apps = sqlsrv_fetch_array($execute_this)) && (sqlsrv_fetch_array($execute_this) <> FALSE)) { //while var has data
if (!isset($row_apps)) die( print_r( sqlsrv_errors(), true));
$count += 1;
echo $row_apps['ApplicationName']." - ".$row_apps['ApproverCode']." - ".$row_apps['ApproverDesc']." - ".$row_apps['FullName']." - ".$row_apps['Email']." - ".$row_apps['UserId']."<br>";
}
/////////////////////////////////////////////////////////////////////////////////
echo "<br><font color=\"blue\">▲ Data displayed.";
echo "<br><br><font color=\"blue\">There were [<font color=\"red\"><b>$count</b></font>] rows returned.<br><br><br>";
echo "<br>\$servername = ";
echo var_dump($servername)."<br>";
echo "<br>\$username = ";
echo var_dump($username)."<br>";
echo "<br>\$password = ";
echo var_dump($password)."<br>";
echo "<br>\$database = ";
echo var_dump($database)."<br>";
echo "<br>\$connection_info = ";
echo var_dump($connection_info)."<br>";
echo "<br>\$conn = ";
echo var_dump($conn)."<br>";
echo "<br>\$application_selected = ";
echo var_dump($application_selected)."<br>";
echo "<br>\$sql_cmd = ";
echo var_dump($sql_cmd)."<br>";
echo "<br>\$execute_this = ";
echo var_dump($execute_this)."<br>";
echo "<br>\$application_proc = ";
echo var_dump($application_proc)."<br>";
echo "<br>\$row_apps = ";
echo var_dump($row_apps)."<br>";
echo "<br>\$count = ";
echo var_dump($count)."<br>";
echo "<br><br><br>";
sqlsrv_close($conn);
echo "<br>DB Connection closed.</font><br><br><br>";
?>
</body>
</html>
it seems my preliminary suspicions (although i had no tangible proof of such) of some sort of db issue was the culprit after pushing my dba (also my director) with some test results from added debug code [like var_dump()/print_r()]. his reply to the issue that caused it all was as follows:
“i don’t know what happened but i copied the table content from my dev environment to your dev environment and now things work.”
i’m sorry to trouble you all with my issue. i am grateful that Marc B and Raad answered my plea for help so quickly and i really hope this question helps someone in the future.