Posted by Toby A Inkster on 05/18/07 08:02
Justin Voelker wrote:
> <?php
> include('/additionalfiles/config.php');
> class SlimStatConfig {
> /** Database connection */
> global $dbhost;
> global $dbuser;
> global $dbpasswd;
> global $dbname;
> var $server = $dbhost;
> var $username = $dbuser;
> var $password = $dbpasswd;
> var $database = $dbname;
> ...
> ?>
<?php
include('/additionalfiles/config.php');
class SlimStatConfig {
/** Database connection */
var $server = $GLOBALS['dbhost'];
var $username = $GLOBALS['dbuser'];
var $password = $GLOBALS['dbpasswd'];
var $database = $GLOBALS['dbname'];
....
?>
Though I'd agree with others that globals are evil. Better to use:
<?php
include('/additionalfiles/config.php');
class SlimStatConfig {
/** Database connection */
var $db;
public function __construct ($db)
{
$this->db = $db;
}
....
?>
And simply pass the object a fully-formed database connection when you
instantiate it.
--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
Navigation:
[Reply to this message]
|