KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Dynamic db name for reports #372

Open Naga Jothi opened this topic on on Jul 14, 2018 - 1 comments

Naga Jothi commented on Jul 14, 2018

Hi,

In my project we have separate db for all customers.We fetch data from db according to the customer login details.So I need to give the db name and settings for reports dynamically when customer logs in.But I can't find the solution for that in koolreport.Can you please help me asap?

KoolReport commented on Jul 14, 2018

Hi Naga,

That's a very nice question of your. It is possible. You can create report object and send customer login through report params, for example:

$report = new DynamicDatabaseReport([
    "db"=>[
        "connectionString"=>"mysql:host=localhost;dbname=your_customer_db"
        "username"=>"customer_login_name",
        "password"=>"password_come_here",
        "charset"=>"utf8"
    ]
]);
$report->run()->render();

And here is your DynamicDatabaseReport.php:

class DynamicDatabaseReport extends \koolreport\KoolReport
{
    function settings()
    {
        return array(
            "dataSources"=>array(
                "db"=>$this->params["db"]
            )
        );
    }

    function setup()
    {
        $this->src("db")
        ->query("...")
        ->pipe(...)
        ...
        ->pipe($this->dataStore("data"));
    }
}

As you can see, you can create a common report for your customers and send the login detail to report so that report can connect to specific customer database to withdraw data.

Hope that helps.

Let me know if you need further assistance.

Regards,

Karl

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
wiki
help needed

None