07-19-2009, 10:11 PM
|
#1 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
The correct way to use multiple classes?
Is this even close to the "correct" way to do this?
main-class.php
PHP Code:
class main_class {
private $someVar = "Hello";
public function talk($text) {
echo $text;
}
public function dispBoard($boardID) {
$sql = "SELECT * FROM " . $config['mysql']['db-name'] . ".threads WHERE board-id =" . $boardID . "ORDER BY date";
$result = mysql_query($sql);
// Then display the board.....
}
}
mysql-class.php
PHP Code:
class mysql_class extends main_class {
protected function connect($host, $username, $password) {
return mysql_connect($host, $username, $password);
}
}
string-class.php
PHP Code:
class string_class extends main_class {
public function trim($str) {
return trim($str);
}
}
What I'm trying to do is be able to call something like this
PHP Code:
$system->mysql_connect($config['mysql']['host'], $config['mysql']['username'], $config['mysql']['password']);
$system->dispBoard(12); // The board ID
It would require more code than that, I didn't feel like writing it all for this post, but is that about the right way to do this? I want the separate "jobs" to be in separate files.
Should I just combine it all into one big file?
|
|
|
|