This example demonstrates how to handle SQL queries and parameters in a Stimulsoft Viewer for PHP. First, include the Stimulsoft libraries:
<?php
require_once '../vendor/autoload.php';

use Stimulsoft\Events\StiDataEventArgs;
use Stimulsoft\Report\StiReport;
use Stimulsoft\Viewer\StiViewer;
?>

Create a Viewer object and configure JavaScript options such as relative paths and additional HTML elements:
$viewer = new StiViewer();
$viewer->javascript->relativePath = '../';
$viewer->javascript->appendHead('<link rel="shortcut icon" href="/../favicon.ico" type="image/x-icon">');

Define viewer events before processing. In this example, onBeginProcessData is used to customize the database connection, SQL queries, and query parameters:
$viewer->onBeginProcessData = function (StiDataEventArgs $args) {
    if ($args->connection == 'MySQL')
        $args->connectionString = 'Server=localhost; Database=northwind; UserId=root; Pwd=;';
    
    if ($args->dataSource == 'MyDataSource')
        $args->queryString = 'SELECT * FROM MyTable';
    
    if ($args->dataSource == 'MyDataSourceWithParams') {
        $args->parameters['Parameter1']->value = 'TableName';
        $args->parameters['Parameter2']->value = 10;
        $args->parameters['Parameter3']->value = '2019-01-20';
    }
};

Process requests on the server side using process():
$viewer->process();

Create a report object and load a report (or dashboard) template using loadFile(). The report will be loaded into a JavaScript object on the client side:
$report = new StiReport();
$report->loadFile('../reports/ManufacturingSQL.mrt');
$viewer->report = $report;

Finally, display the viewer using printHtml():
$viewer->printHtml();

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.