Rendering a Report with SQL from Code on the Server-Side
Our sample projects and report templates can help you learn the basics of working with our products.Prepare the data in PHP, register it in the report dictionary, and render the template with those records.
Preparing the data. Read or create the data source, register it in the report dictionary, synchronize the schema, and render with the supplied records.
The event fires on the server as data is processed, so a headless render can query databases securely, with the connection string and query controlled entirely in PHP.
Preparing the data. Read or create the data source, register it in the report dictionary, synchronize the schema, and render with the supplied records.
$report->engine = StiEngineType::ServerNodeJS;
$report->onBeginProcessData = function (StiDataEventArgs $args) {
if ($args->connection == 'MyConnectionName')
$args->connectionString = 'Server=localhost; Database=northwind; UserId=root; Pwd=;';
if ($args->dataSource == 'MyDataSource')
$args->queryString = 'SELECT * FROM MyTable';
};
$report->process();
$report->loadFile('reports/SimpleListSQL.mrt');
$report->render();engine = StiEngineType::ServerNodeJS— renders on the server with the Node.js engine.onBeginProcessData— fires on the server as data is processed, keeping the connection details in PHP.$args->connectionString / queryString— supply the database connection and SQL query for the headless render.
The event fires on the server as data is processed, so a headless render can query databases securely, with the connection string and query controlled entirely in PHP.