פורסם בתאריך Monday, September 06, 2010 4:22 PM על ידי Guy Burstein | ישנם 2 תגובות

PHP SDK Reporting Servicesמיקרוסופט שחררה לאחרונה גירסא ראשונה של SDK ל- PHP עבור כלי הדוחות SQL Server Reporting Services. הפרוייקט משוחרר בקוד פתוח באתר CodePlex תחת רשיון MS-Pl.

ה- SDK מאפשר לאפליקציות PHP לעשות שימוש בכלי הדוחות וה- BI של מיקרוסופט – SQL Server Reporting Services. יתרה מכך, ניתן אפילו לעשות שימוש ביכולות האלה בעת שימוש בגירסא החינמית המורחבת של SQL Server ששמה SQL Server 2008 Express with Advanced Services edition. הגירסא המורחבת הזאת כוללת את מנוע בסיס הנתונים SQL Server 2008 Express וגם ממשק ניהול ורכיבי צד השרת הנדרשים לצורך הפעלת שרת ה- Reporting Services, לצורך יצירה, ניהול והרצה של דוחות טבלאיים, מטריציונים, וכו’.

הורידו בחינם את SQL Server 2008 Express with Advanced Services.

ה- SDK מציע API פשוט לעבודה מול SQL Server Reporting Services. במסגרת ה- SDK יש מספר פונקציות המאפשרות לעשות שימוש ביכולות הנפוצות:

  • קבלת רשימת הדוחות הזמינים מתוך אפליקציית PHP
  • העברת פרמטרים לדוחות מתוך טופס
  • שליטה באופן התצוגה של הדוחות

דוגמת קוד:

<?php
// 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>';
?>

תהנו!