PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
<?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;
}
?>
// MySQL server name
$this->mysqlserver = 'localhost';
// MySQL database user
$this->dbuser = 'username';
// MySQL database name
$this->dbname = 'databasename';
// MySQL database password
$this->dbpwd = 'password';
// show flag of visitor
// option are: 1 show flags, 0 do not show flags
$this->countryflags = 1;
// flag extension
$this->imageextension = '.png';
// flag directory
$this->countryflagspath = 'images/flags';
Then just call the class from inside the other class.
// MySQL server name
$this->mysqlserver = 'localhost';
// MySQL database user
$this->dbuser = 'username';
// MySQL database name
$this->dbname = 'databasename';
// MySQL database password
$this->dbpwd = 'password';
// show flag of visitor
// option are: 1 show flags, 0 do not show flags
$this->countryflags = 1;
// flag extension
$this->imageextension = '.png';
// flag directory
$this->countryflagspath = 'images/flags';
Then just call the class from inside the other class.
I am doing something wrong because I cannot get this to work. Does the above get added to the actual class code already in config.php, or should it replace the top part of that file. Also, how do I call the class inside the reports.php file. I have always used includes up to now so this is a bit strange still.