I have the following class:
class MySQLDatabase
{
private $connection;
public $last_query;
private $magic_quotes_active;
private $real_escape_string_exits;
public function __construct()...
// 1. OPENS connection and selects a DB
public function open_connection()...
// 2. PERFORMS a DB query
public function query($sql)
{
$this->last_query = $sql;
$result = mysql_query($sql, $this->connection);
$this->confirm_query($result);
return $result;
}
....
NOTE: I included a few lines that are extraneous to my question just to lend some context, they are denoted by ...
Focusing on public function query($sql), I’m confused by what I see.
- the
$sqlvariable in the method is not defined anywhere other than here, and I believe it’s a parameter variable, as in my IDE it’s colored slightly differently from other variables. What does that mean and why is it different? $this->last_queryis also a variable, but needs to be defined within the class, as seen at the top of the class itself. Why does this one need to be defined as such, while the$sqlvariable did not?- And finally,
$resultappears to be a standard variable, not a “parameter variable” — I hope I’m using the right language. Why is this one not defined also? Why is it used like this within this class?
I’m really hoping to understand the differences between these guys so I can get a better handle on using them.
Thanks in advance for you help!
Above variables are member variables of your class. They are available inside any function of your class and they can be accessed with
$this->.$sqlis the parameter of yourqueryfunction meaning that its scope is only inside this function and can not be accessed from within any other function. The same applies for the local variable$result. It is also only available inside thequeryfunction.