Documentation:

Back
phpchartPlus Documentation
Tsiavos Chris <[email protected]>
Date: 18-Feb-2005
License: GPL
3.3.3 Using the CacheToPEARDB Strategy
requires PEAR DB pear.php.net
To use the CacheToPEARDB Strategy you have to follow a 4 steps process:
1. Create a database with a table having 3 fields where the image name, the image data (in binary) and the image modification time will be hold correspondingly.
2. Include the CacheToPEARDB_Strategy.php file in your source code
3. Initialize the CacheToPEARDB Strategy class
4. Strategize the phpchartPlus instance with the CacheToPEARDB Strategy instance passing as parameters:
  • the validity period (in minutes) of the cached copy.
  • the database connection parameters
To specify the database connection parameters you need a 9-slot associative array with the following keys defined:

- DB_Type: the name of the database server (mysql,pgsql etc)
- DB_Username: the database username
- DB_Passwd: the database user password
- DB_Host: the DNS name or ip number of the database server
- DB_Name: the name of the database
- Field_ImageName: the name of the table field holding the name of the cached image copy
- Field_ImageData: the name of the table field holding the binary data of the cached image copy
- Field_ImageModification: the name of the table holding the modification time of the cached image copy.
code portion from file: "Examples/example.php"
include("../Sources/phpchartPlus.php");
include("../Sources/CacheToPEARDB_Strategy.php");
include("../Sources/XMLData_Strategy.php");
include("../Sources/PHPConfig_Strategy.php");
 
$CacheParams=array("DB_Type"=>"",
                   "DB_Username"=>"",
                   "DB_Passwd"=>"",
                   "DB_Host"=>"",
                   "DB_Name"=>"",
                   "DB_Table"=>"",
                   "Field_ImageName"=>"",
                   "Field_ImageData"=>"",
                   "Field_ImageModification"=>"");
 
$DataParams=array("filename"=>"../Data/ChartData.xml");
 
$ConfigParams=array("ImageWidth"=>420,
                    "ImageHeight"=>300,
                    "ImageOutputType"=>"png",
                    "ChartTitle"=>"Web Servers Usage",
                    "ChartType"=>"Area",
                    "ChartUseBlending"=>"Yes",
                    "ChartUseAntialias"=>"Yes",
                    "ChartHmargin"=>30,
                    "ChartVmargin"=>25,
                    "ChartUseStatus"=>"Yes",
                    "ChartBgImage"=>"../Data/bgimage.png",
                    "ImageColor_Start"=>"DimGray",
                    "ImageColor_Finish"=>"DimGray",
                    "ImageColor_Alpha"=>70,
                    "ChartColor_Start"=>"DimGray",
                    "ChartColor_Finish"=>"FloralWhite",
                    "ChartColor_Alpha"=>50,
                    "FontColor"=>"White",
                    "FontWidth"=>3,
                    "FontHeight"=>3,
                    "LegendColors"=>
                     array("DarkRed,Yellow","Black,DarkGreen"),
                    "LegendColors_Alpha"=>array(30,60),
                    "GridNum"=>4,
                    "GridMinValue"=>0,
                    "GridMaxValue"=>100,
                    "GridColor"=>"Black");
 
$DataStrategy=new XMLData_Strategy();
$ConfigStrategy=new PHPConfig_Strategy();
$CacheStrategy=new CacheToPEARDB_Strategy();               
$im=new phpchartPlus();
                   
try
   {
     $im->DataParser_->strategize($DataStrategy,$DataParams);
     $im->DataParser_->parse();
   }
   catch (DataParser_Exception $e) 
   {
     print $e->getMessage();
     exit();
   }
   catch (DataStrategy_Exception $f) 
   {
     print $f->getMessage();
     exit();
   }

try
   {
     $im->ConfigParser_->strategize($ConfigStrategy);
     $im->ConfigParser_->parse($ConfigParams);
   }
   catch (ConfigParser_Exception $e) 
   {
     print $e->getMessage();
     exit();
   }
   catch (ConfigStrategy_Exception $f) 
   {
     print $f->getMessage();
     exit();
   } 
   
try
   {
     $im->get_Instance();
   }
   catch (ImageSupport_Exception $e)
   {
     print $e->getMessage();
     exit();
   }
   catch (FontSupport_Exception $f)
   {
     print $f->getMessage();
     exit();
   }
                   
try
{
$im->Chart_->set_CachingStrategy($CacheStrategy,2,$CacheParams); 
//Cache for 2 minutes
}
catch (CachingStrategy_Exception $e)
{
  print $e->getMessage();
  exit();
}
   
$im->Chart_->draw_Chart();              
 

 
Hosted by www.Geocities.ws

1