KoolReport's Forum

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

Help Connecting to mySql database #2644

Open Ray Pierce opened this topic on on Apr 21, 2022 - 8 comments

Ray Pierce commented on Apr 21, 2022

Hello, I am having a hard time understanding how to make KoolReport work. I have managed to get the examples working on my server, but these are connected to static data in CSV or some other form. I want to simply use the examples and modify them to suit my purpose.

I downloaded KoolReport and have inserted here the file for the "Minimum Settings" table.

<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>array(
                        array("name","age","income"),
                        array("John",26,50000),
                        array("Marry",29,60000),
                        array("Peter",34,100000),
                        array("Donald",28,80000),
                    )
                )
            )
        );
    }
    protected function setup()
    {
        $this->src("data")
        ->pipe($this->dataStore("data"));
    }    
}

How do I convert this table to use my data?? The examples given on with the example table aren't clear to me.

Getting started with Table is very easy! All you need to do is to provide "dataSource" for table, for example:

<?php
Table::create(array(
    "dataSource"=>$this->dataStore('data')
));
?>
Use SQL Query

Table can receive direct query, for example:

<?php 
Table::create(array(
    "dataSource"=>$this->src("mysql_database")->query("select * from orders")
));
?>
Use Array

<?php 
Table::create(array(
    "dataSource"=>array(
        array("name","age"),
        array("Peter",35),
        array("John",36)
    )
));
?>
or associate array

<?php 
Table::create(array(
    "dataSource"=>array(
        array("name"=>"Peter","age"=>35),
        array("name"=>"John","age"=>36)
    )
));
?>

The examples given look nothing like the actual files that are supplied in the downloaded files. Are there any step by step instructions for people who are not computer programmers to use?? This is not easy for me to grasp with the tutorials supplied. The examples are wonderful if I could use them. I would by=uy the Pro version but don't want to pay for something I won't be able to easily use.

Thank you for any help.

Ray

Sebastian Morales commented on Apr 22, 2022

Hi Ray, pls copy and modify the following example to connect to your mysql database:

https://www.koolreport.com/examples/reports/datasources/mysql_report/

Let us know if you have any difficulty. Tks,

Ray Pierce commented on Apr 22, 2022

Hi Sebastian,

I have copied the file structure from the MySQL you referenced. I tried to modify it to connect to my db but get errors in the connecting. Here is the generated error log:

[22-Apr-2022 03:49:54 UTC] PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'my_username'@'my.server.com' (using password: YES) in /home/my_site/public_html/koolreport/core/src/datasources/PdoDataSource.php:121
Stack trace:
#0 /home/my_site/public_html/koolreport/core/src/datasources/PdoDataSource.php(121): PDO->__construct('mysql:host=4thc...', 'my_site_user...', 'password', NULL)
#1 /home/my_site/public_html/koolreport/core/src/core/DataSource.php(57): koolreport\datasources\PdoDataSource->onInit()
#2 /home/my_site/public_html/koolreport/core/src/KoolReport.php(264): koolreport\core\DataSource->__construct(Array, Object(audit_count))
#3 /home/my_site/public_html/safety_reports/audit_count.php(28): koolreport\KoolReport->src('audit_count')
#4 /home/my_site/public_html/koolreport/core/src/KoolReport.php(100): audit_count->setup()
#5 /home/my_site/public_html/safety_reports/index.php(4): koolreport\KoolReport->__construct()
#6 {main}
  thrown in /home/my_site/public_html/koolreport/core/src/datasources/PdoDataSource.php on line 121

It appears that I'm getting closer, but I'm no coder and am stuck. I am using the correct password and username for my db.

Thank you for helping!

Ray

Sebastian Morales commented on Apr 22, 2022

I think this is a Mysql permission problem with your user from your server. For example, your mysql user could have been granted access from localhost (user@localhost) but not your server address or * (anywhere). To solve this pls use the following grant command in your database:

GRANT SELECT ON *.* TO 'my_username'@'my.server.com';

Let us know if there's any error.

Ray Pierce commented on Apr 22, 2022

I access this database from other apps and reports that I've created with no problems. I have several instances of Moodle LMS on this server which are MySQL intensive, and they have no issue connecting to databases. Is there some other possible reason I'm having the issue with Koolreport??

Ray Pierce commented on Apr 24, 2022

????

Sebastian Morales commented on Apr 25, 2022

Pls run this sql query on your database to see whether your db user and host exist:

SELECT user, host FROM mysql.user

Or you can open a terminal on your web server and try to connect via mysql command:

mysql -u USERNAME -h HOSTNAME DATABASENAME -p

Replace username, hostname, dbname with your own and fill in the password.

Ray Pierce commented on Apr 25, 2022

Thank you, I will work on this!

cristydavidd commented on Nov 8, 2022

In some of the ways, spacing and the order of parameters in the MySql connection string does matters. So, stick to the standard format:

MysqlConn.ConnectionString = "Server=localhost;Port=1234;Database=My_Mysql_Database;Uid=root;Pwd=root;"

If the above connection string fails, try update your c# mysql connection string as shown below (without port variable as well):

MysqlConn.ConnectionString = "Server=localhost;Database=My_Mysql_Database;Uid=root;Pwd=root;"

Or, sometime the problem could be on your windows firewall, make sure your server allow access to all port associated with your mysql database.

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
None yet

None