MySQLDataSource

Introduction #

Although using PDODataSource can connect to MySQL. However if for some reasons, you do not have the PDO Driver, you may use the old traditional connection to MySQL using MySQLDataSource

Settings #

Nametypedefaultdescription
classstringMust set to '\koolreport\datasources\MySQLDataSource'
hoststringHost of database
usernamestringYour login username
passwordstringYour password
dbnamestringDatabase name
charsetstringCharset

Methods #

Namereturndescription
query(string $str_query)MySQLDataSourceThis method is used in report's setup() function. It will help to setup query string which will be executed when report is run.
params(array $params)MySQLDataSourceThis method is used to set list of parameters for query statement

Example #

<?php
class MyReport extends \koolreport\KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "automaker"=>array(
                    'host' => 'localhost',
                    'username' => 'root',
                    'password' => '',
                    'dbname' => 'automaker',
                    'charset' => 'utf8',  
                    'class' => "\koolreport\datasources\MySQLDataSource"  
                ),
            )
        );
    }
    public function setup()
    {
        $this->src('automaker')
        ->query("SELECT * FROM tblPurchase where status=:status")
        ->params(array(":status"=>"completed"))
        ->pipe(..)
        ->pipe(..)
        ->pipe($this->dataStore('purchase_summary'));
    }
}

In above example, we query all data from table tblPurchase of "automaker". The query result will be piped through many processes in between until it reaches the final data store called "purchase_summary".