I have a PHP web service running using NuSoap. I have a PHP function that executes a stored procedure on a MSSQL server. I am trying to understand how I can pass a C# Dictionary to the webservice so that it can be consumed like an associative array by PHP.
Assume the project is far enough along where I am locked into NuSoap and C#. I'm open to changing the PHP function though and passing my C# params in a different way if this method isn't possible.
The PHP function was written to use an associative array like so:
function runReport($input) {
global $cwlink;
$query = "EXEC localhost.dbo.".$input['report'];
$first = true;
foreach ($input as $key => $value) {
if($first) {
$first = false;
continue;
}
$query .= " @".$key." = '".$value."',";
}
$query = substr($query, 0, -1);
$results = mssql_query($query, $cwlink);
$rows = mssql_fetch_array($results);
$return = array();
do {
do {
$return[] = $rows;
}while($rows = mssql_fetch_array($results));
}while(mssql_next_result($results));
return $return; }
In the end, I ended up modifying my input array to expect a standard array and separated out my report name and my input parameters as two separate inputs.
function runReport($reportName, $input)
{
global $cwlink;
$query = "EXEC localhost.dbo.".$reportName;
for ($i = 0; $i < count($input); $i = $i + 2) {
$query .= " @".$input[$i]." = '".$input[$i + 1]."',";
}
$query = substr($query, 0, -1);
$results = mssql_query($query, $cwlink);
$rows = mssql_fetch_array($results);
$return = array();
do {
do {
$return[] = $rows;
}while($rows = mssql_fetch_array($results));
}while(mssql_next_result($results));
return $return;
}