Config files and classes
Posted: Wed Mar 31, 2004 3:26 pm
I have 2 files as below. The first is a general config file that holds variables used throughout. The second is a class that will eventually create some reports. How do I call the config class inside the reprts class. I hope this makes sense, it's the first time I have tried to use classes.
Config.php
Reports.php
Config.php
Code: Select all
<?php
//create new config class
$conf = new Config();
// MySQL server name
$conf->mysqlserver = 'localhost';
// MySQL database user
$conf->dbuser = 'username';
// MySQL database name
$conf->dbname = 'databasename';
// MySQL database password
$conf->dbpwd = 'password';
// show flag of visitor
// option are: 1 show flags, 0 do not show flags
$conf->countryflags = 1;
// flag extension
$conf->imageextension = '.png';
// flag directory
$conf->countryflagspath = 'images/flags';
class Config
{
// MySQL server name
var $mysqlserver;
// MySQL database user
var $dbuser;
// MySQL database name
var $dbname;
// MySQL database password
var $userpwd;
// show flag of visitor
var $countryflags;
// flag extension
var $imageextension;
// flag directory
var $countryflagspath;
}
?>Code: Select all
<?
class Reports
{
function Reports()
{
$this->startTimer();
}
function country()
{
echo "<img src='gb.png'>";
}
function startTimer()
{ //function to start the timer.
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$this->starttime = $mtime;
}
function endTimer()
{ //function to end the timer.
$mtime = microtime ();
$mtime = explode (' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = round (($endtime - $this->starttime), 5);
return $totaltime;
}
}
?>