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:

  1. 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.
  2. In above example, we have two sources "mysql_datasource" and "csv_datasource". Those sources are named by yourself.
  3. The "mysql_datasource" uses default PdoDataSource to connect to MySQL Server while the "csv_datasource" use \koolreport\datasources\CSVDataSource to work with CSV file.