Outsite Variable inside a Class
Posted: Wed Aug 20, 2008 3:49 pm
I have a config file that contains variables that differ local vs remote, such as db information.
In a class I have the config file included and have a function in the class to connect to the db:
Do access modifiers reset the variables from the config file? How do I get the two to work together without calling the function like so:??????
Code: Select all
if (stristr($_SERVER['HTTP_HOST'], 'local')||(substr($_SERVER['HTTP_HOST'],0,7)=='192.168')){
$db_address="localhost";
$db_user="root";
....
}
Code: Select all
public function dbConnect(){
mysql_connect($this->db_address,$this->db_user,$this->db_pass) or die (mysql_error());
mysql_select_db($this->db_database) or die (mysql_error());
}Code: Select all
//This is ok
public function dbConnect($db_address,$db_user,$db_pass,$db_database){
mysql_connect($db_address,$db_user,$db_pass) or die (mysql_error());
mysql_select_db($db_database) or die (mysql_error());
}
//I don't like this:
$category->dbConnect($db_address,$db_user,$db_pass,$db_database);
//I do like this:
$category->dbConnect();