DataSource
Overview #
DataSource is used to connect to your source of data, pull data rows by rows and pipe them into datapipe. In the settings()
methods of our report, we define our list of datasources and their connection settings.
Sample code #
<?php
class MyReport extends \koolreport\KoolReport
{
protected function settings()
{
return array(
"dataSources"=>array(
"mysql_datasource"=>array(
"connectionString"=>"mysql:host=localhost;dbname=mysql_databases",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
),
"csv_datasource"=>array(
"class"=>'\koolreport\datasources\CSVDataSource'
"filePath"=>"/var/public/data/sales.csv"
),
)
);
}
....
}
Code explanation:
- The
settings()
methods return an array and one of key value in the settings is"dataSources"
containing list of all your source of data. 2."dataSources"
contains list of key-value in which key is the name of source and the value is the connection settings of that sources. - In above example, we have two sources
"mysql_datasource"
and"csv_datasource"
. Those sources are named by yourself. - The
"mysql_datasource"
uses defaultPdoDataSource
to connect to MySQL Server while the"csv_datasource"
use\koolreport\datasources\CSVDataSource
to work with CSV file.
Get started with KoolReport
KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.