Greetings everyone!

As promised, new exciting features are bundled in this release! Now you can integrate database with your charts using simple sql query. Read more to learn about basic steps to integrate database below.

First Step is to set database configuration in config.php.

To connect to MySqli:

define(“CHARTPHP_DBTYPE”,”mysqli”);
define(“CHARTPHP_DBHOST”,”localhost”);
define(“CHARTPHP_DBUSER”,”user”);
define(“CHARTPHP_DBPASS”,”pass”);
define(“CHARTPHP_DBNAME”,”northwind”);

To connect using PDO:

define(“CHARTPHP_DBTYPE”,”pdo”);
define(“CHARTPHP_DBHOST”,”sqlite:../../sampledb/Northwind.db”);
define(“CHARTPHP_DBUSER”,””);
define(“CHARTPHP_DBPASS”,””);
define(“CHARTPHP_DBNAME”,””);

Next is to include configuration file in your code.

include(“../../config.php”);

Final Step is to define data_sql property, that will load data points from database.

$p->data_sql = “select c.categoryname, sum(a.quantity) as ‘Sales 1997’, sum(a.quantity)+1000 as ‘Sales 1998’
from products b, `order details` a, categories c
where a.productid = b.productid and c.categoryid = b.categoryid
group by c.categoryid
order by c.categoryid”

And the result …

Resources

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?