Database Integration

Database Integration

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
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 …

bar-db-chart

Resources