Hi I have a question regarding following code, which i got from a turorial
********** varaiable.php ************
<?
$GLOBALS['db_host'] = "host"
$GLOBALS['db_user'] = "user"
$GLOBALS['db_pass'] = "pass"
$GLOBALS['db'] = "db"
?>
********* classphp.php ******************
include "variable.php"
<?
class db_qur
{
function db_qur() {
$this->db_host = $GLOBALS['db_host'];
$this->db_user = $GLOBALS['db_user'];
$this->db_pass = $GLOBALS['db_pass'];
$this->db = $GLOBALS['db'];
$GLOBALS['connection'] = mysql_connect($this->db_host, $this->db_user, $this->db_pass)
or die( "Unable to connect to SQL server");
mysql_select_db($this->db)
or die( "Unable to select database");
}
}
?>
why are we doing
$this->db_host = $GLOBALS['db_host'];
why don't just
db_host = $GLOBALS['db_host'];
Isn't the purpose of doing
$this->db_host = $GLOBALS['db_host'];
so that variable can accessed with out being passed to the function. But here we are passing the varaibles any way
$GLOBALS['connection'] = mysql_connect($this->db_host, $this->db_user, $this->db_pass)
so what the point doing
$this->db_host = $GLOBALS['db_host'];
Thanks
********** varaiable.php ************
<?
$GLOBALS['db_host'] = "host"
$GLOBALS['db_user'] = "user"
$GLOBALS['db_pass'] = "pass"
$GLOBALS['db'] = "db"
?>
********* classphp.php ******************
include "variable.php"
<?
class db_qur
{
function db_qur() {
$this->db_host = $GLOBALS['db_host'];
$this->db_user = $GLOBALS['db_user'];
$this->db_pass = $GLOBALS['db_pass'];
$this->db = $GLOBALS['db'];
$GLOBALS['connection'] = mysql_connect($this->db_host, $this->db_user, $this->db_pass)
or die( "Unable to connect to SQL server");
mysql_select_db($this->db)
or die( "Unable to select database");
}
}
?>
why are we doing
$this->db_host = $GLOBALS['db_host'];
why don't just
db_host = $GLOBALS['db_host'];
Isn't the purpose of doing
$this->db_host = $GLOBALS['db_host'];
so that variable can accessed with out being passed to the function. But here we are passing the varaibles any way
$GLOBALS['connection'] = mysql_connect($this->db_host, $this->db_user, $this->db_pass)
so what the point doing
$this->db_host = $GLOBALS['db_host'];
Thanks