![]() |
Advanced Graphs and Charts for PHP |
Database Information FileWith this method the database information file will contain the necessary information for the graphng software to connect to your database and the queries to run for each data series. At runtime the graphing software will read this file, connect to the database and execute each of the queries. It will then automatically extract the data from the result set(s) for plotting on the graph. The database information file is a PHP script which assigns various options to a PHP array '$jpDatabase'. This file is used by the graphing software to connect to the database and execute the queries. The array contains three sections of information:-
An example file can be found in the Sample Application directory ./jpowered/sampleApplication/dataQueries/dbConfig.php
To tell the graph to use a database information file the 'data' parameter of the IMG tag should be replaced with 'dbinfo' parameter, like this:-
Database Connection Information
Data Queries
The above example will provide the graph with a single value for each data point. However some graph styles require 2 or 3 values (e.g. the X-Y scatter graph requires 2 values and the Bubble chart requires 3 values for each data point). For these graph styles the format would be like this:- NOTE: All PHP Global variables ($_REQUEST, $_GET, $_POST, $_SESSION etc) are available to be used within the database information file. For instance if
you wish to dynamically construct a query based on the value of "userID" held in the session then you could do something like this:-
Database Abstraction Code
Putting it all together the database information file should look like this:-
Also see:- |