PdoDataSource

Introduction #

PdoDataSource is the default datasource in KoolReport. This datasource helps you to connect to various databases such as MySQL, SQL Server, Oracle and many others.

Supported Databases:

  • CUBRID (PDO)
  • MS SQL Server (PDO)
  • Firebird (PDO)
  • IBM (PDO)
  • Informix (PDO)
  • MySQL (PDO)
  • MS SQL Server (PDO)
  • Oracle (PDO)
  • ODBC and DB2 (PDO)
  • PostgreSQL (PDO)
  • SQLite (PDO)
  • 4D (PDO)

For more information of PDO, click here!

Settings #

Nametypedefaultdescription
connectionobjectSet the connection object
connectionStringstringSet the PDO connection string
usernamestringUser login name
passwordstringUser password
charsetstring"utf8"Set the charset of database.

If connection is set to an existed connection, that connection object will be used.

Otherwise, KoolReport will create a new or use a previously own-created connection object of the same setting.

Connection string examples #

MySQL:

'mysql:host=127.0.0.1:3306;dbname=automaker'

PostgreSQL:

'pgsql:host=localhost;dbname=automaker'

SQL Server:

'sqlsrv:server=localhost;Database=automaker'

Oracle:

'oci:dbname=//localhost:1521/ORCLCDB'

MongoDB:

'mongodb://localhost:27017'

Methods #

Namereturndescription
query(string $str_query)PdoDataSourceThis method is used in report's setup() function. It will help to setup query string which will be excuted when report is run.
params(array $params)PdoDataSourceThis 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(
                "mysql_datasource"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=mysql_databases",
                    "username"=>"root",
                    "password"=>"",
                    "charset"=>"utf8"
                ),
            )
        );
    }

    public function setup()
    {
        $this->src('mysql_datasource')
        ->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 "mysql_datasource". The query result will be piped through many processes in between until it reaches the final data store called "purchase_summary".

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.