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();

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.