SQL Report
A report can be generated just from supplying the database connection details and an sql statement. The report column labels are derived from the column names, so if a column is for example customer_address, then the label will automatically be set to "Customer Address". Use an SQL alias to specify a better label. Also use an alias for SQL expressions like COUNT(*) or SUM(x) to get a sensible column label.Note that you cannot yet use the SELECT * notation you have to specify the individual columns.
<?php
\Reportico\Engine\Builder::build()
...
...
->datasource()->database("mysql:host=localhost; dbname=<DATABASENAME>")->user("<DATABASE USER>")->password("<DATABASE PASSWORD>")
->sql ("
SELECT column1, column2, column3 AS some_alias, expression * 2 as some_label
FROM table
ORDER BY column1
")
...
...
->execute();
?>
1
<?php
require_once(__DIR__ .'/../vendor/autoload.php');
\Reportico\Engine\Builder::build()
->properties([ "bootstrap_preloaded" => true])
->datasource()->database("mysql:host=localhost; dbname=DATABASE NAME")->user("USER")->password("PASSWORD")
->title ("Employee List")
->description ("Produces a list of our employees")
->sql ("
SELECT EmployeeID employee_id, LastName last_name, FirstName first_name, BirthDate birth_date, Country
FROM northwind_employees
ORDER BY Country, LastName
")
->execute();
?>