Overview
Code Sample
Contributors
Overview
The
SQL Server Reporting Services (SSRS) SDK for PHP is a library that uses the SQL Server Reporting Services SOAP APIs to enable PHP developers to leverage the SSRS Business Intelligence/Reporting features in their application.
The library is designed to make simple for developers to call the SSRS remote APIs to perform the following operations:
- Query for the list of reports available on the server
- Query for the list of parameters required for each report with the list of valid values
- Query the list of Formats supported by the Server
- Execute a Report
Additional links and information can be found on the Interoperability Bridges website:
http://www.interoperabilitybridges.com/projects/sql-server-reporting-services-sdk-for-php
Code Sample
// include the SSRS library
require_once 'SSRSReport.php';
define("REPORT", "/AdventureWorks 2008 Sample Reports/TopStoresBegin");
$settings = parse_ini_file("app.config", 1);
// Create a connection to the SSRS Server
$rs = new SSRSReport(new Credentials($settings["UID"], $settings["PASWD"]),$settings["SERVICE_URL"]);
// Load the report and specify the params required for its execution
$executionInfo = $rs->LoadReport2(REPORT, NULL);
$parameters = array();
$parameters[0] = new ParameterValue();
$parameters[0]->Name = "ProductCategory";
$parameters[0]->Value = "1";
$parameters[1] = new ParameterValue();
$parameters[1]->Name = "StartDate";
$parameters[1]->Value = "1/1/2003";
$parameters[2] = new ParameterValue();
$parameters[2]->Name = "EndDate";
$parameters[2]->Value = "12/31/2003";
$parameters[3] = new ParameterValue();
$parameters[3]->Name = "ProductSubcategory";
$parameters[3]->Value = "2";
$rs->SetExecutionParameters2($parameters);
// Require the Report to be rendered in HTML format
$renderAsHTML = new RenderAsHTML();
// Set the links in the reports to point to the php app
$renderAsHTML->ReplacementRoot = getPageURL();
// Set the root path on the server for any image included in the report
$renderAsHTML->StreamRoot = './images/';
// Execute the Report
$result_html = $rs->Render2($renderAsHTML,
PageCountModeEnum::$Actual,
$Extension,
$MimeType,
$Encoding,
$Warnings,
$StreamIds);
// Save all images on the server (under /images/ dir)
foreach($StreamIds as $StreamId)
{
$renderAsHTML->StreamRoot = null;
$result_png = $rs->RenderStream($renderAsHTML,
$StreamId,
$Encoding,
$MimeType);
if (!$handle = fopen("./images/" . $StreamId, 'wb'))
{
echo "Cannot open file for writing output";
exit;
}
if (fwrite($handle, $result_png) === FALSE)
{
echo "Cannot write to file";
exit;
}
fclose($handle);
}
// include the Report within a Div on the page
echo '<html><body><br/><br/>';
echo '<div align="center">';
echo '<div style="overflow:auto; width:700px; height:600px">';
echo $result_html;
echo '</div>';
echo '</div>';
echo '</body></html>';
Contributors
 |  |
| Microsoft is the project sponsor and provides architectural guidance and best practices for this SDK. | Persistent Systems Ltd. is an award-winning technology company specialized in software product development services. The Company’s proven processes for entire product lifecycle helps customers increase revenue, margin and enhance brand value. |