• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1858
  • Last Modified:

Pass PHP variables to SSRS

Is there a way to pass a PHP variable to SSRS? I'm trying to capture the value of $var1 in a PHP page and pass it into a report built in SSRS 2008 as @var1. Anyone know of a way to do this?
0
dsurrett2
Asked:
dsurrett2
1 Solution
 
Tyler LaczkoCommented:
I am unfamiliar with SSRS but would writing the PHP variable to a hidden input box work?
0
 
Megan BrooksSQL Server ConsultantCommented:
It depends upon where you are hosting the report viewer. If it is contained within a web application then the app itself determines how you pass a parameter to it. If you simply wish to redirect from a PHP page to Report Manager (RM) or the report viewer that is built in to Report Server (RS) then you can include the report parameter in the RM or RS URL as an URL query parameter (case sensitive). The URL might look something like this for a parameter called "rptParam" with a value of "xxx":

http://<reportserverhost>/Reports/Pages/Report.aspx?ItemPath=/reportpath/reportname&rptParam=xxx

or

http://<reportserverhost>/ReportServer/Pages/ReportViewer.aspx?/reportpath/reportname&rptParam=xxx

You can determine the exact URL by interactively displaying the report using RM or RS.

This is approach is OK within an intranet. You might want to take a different approach out on the Internet.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
dsurrett2Author Commented:
I probably should have included a bit more info. I'm already using the PHP SDK from the codeplex site. I really would rather NOT have the parameter passed in as part of the URL since the parameter is used for the following purposes in my web application:

1. Restrict access to data on the screen (essentially a group ID)
2. Restrict access to data on a report (again, much like a group ID)

The problem I have is as follows:

I can easily declare and pass the group ID as a variable within PHP and all PHP code will recognize this group ID. However, if I want to use this same group ID in my SSRS report, I need to somehow pass the value of this PHP variable to a similar variable in my report as soon as I launch the report from the PHP page.

So in PHP I declare and populate a variable called $group, which is used to limit the data on the page. The user clicks a button to launch a report (using the PHP SDK) and the report query needs to be filtered by whatever value is stored in PHP as $group. By placing this value in the url, a user could potentially change the group to a different value and accidentally gain access to data intended for a different group. I appreciate all the feedback and hopefully this additional info will help guide those who know more about this than I do.
0
 
Megan BrooksSQL Server ConsultantCommented:
I am not familiar with the SSRS SDK for PHP, but from glancing at some of the information about it I have the impression that it can send a request to the SSRS execution web service and return HTML (or other format) via the Render method, for direct output without using the ReportViewer control.

You will need to pass an additional parameter ($group) to the execution web service prior to rendering, one that is not supplied by the web page user interface. It looks like you would use the $rs->SetExecutionParameters2() method.

In my ASP.NET web apps I like to designate certain standard parameter names that are automatically populated when present. For example, if a report contains a hidden parameter called UserID then the web app might populate it automatically with the user's ID as assigned by the web app when rendering that report. The app uses GetExecutionParameters() to check for special parameter names.

As long as the user doesn't have direct access to the reports on the report server (and the web app does), you can prevent a user from substituting a different parameter value. Make sure that the only path the user has to the report is through your web app.
0
 
dsurrett2Author Commented:
rscowden, that sounds like it might work. I'll give that a try and report back. Thanks much!
0
 
dsurrett2Author Commented:
Ok, so here is what I did to get this to work...

First, load the report and get the list of parameters from the execution info as follows:

$stdObject = $report->loadReport($Name);
$reportParams = get_object_vars ($stdObject);
$reportParams = $reportParams["executionInfo"]->Parameters->ReportParameter;

Next, a PHP script builds a screen using a function that iterates through the list of report parameters, building an HTML input field element for each report parameter based on its attributes. In the below examples, $$x is a parameter. "Hidden" report parameters, as this one was to be, have the property "$$x->PromptUser" set to true, but have an empty string, "", in the "$$x->Prompt" field (at least as of Report Builder 2.0). Using the "variable variable" syntax in combination with a double-quoted string, the sript is set up to check for potential valid values in the current php scope to put into the report parameter (Other checks preclude any parameters that have "$$x->PromptUser" set to false or have something in "$$x->Prompt").

else if ($$x->Prompt == "") {
  $html .= "value='${${$x}->Name}' ";
}

Once the form has been filled out by the user, the list of report parameters is applied to the current report by creating an array called "$parameters" and calling the "$group->SetExecutionParameters2" function, passing it the array of parameters and the language for the report, like the following lines:

$executionInfo2 = $group->SetExecutionParameters2($reportParameters,"en-us");
$objectVars = get_object_vars ($executionInfo2);

The report is then rendered as HTML.
0
 
dsurrett2Author Commented:
Solution was very general but did point me in the right direction.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now