php_guest Posted January 17, 2009 Share Posted January 17, 2009 I am looking at code where class is created. On the line 8 is "...$this->connection)". Please explain me when do we use $this->. I thought first that we use it for variable inside function which is declared inside class creation. But I see I am wrong because than it should be also before result and q in the same line $this->. class MySQLDB { function usernameTaken($username){ if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "SELECT username FROM ".TBL_USERS." WHERE username = '$username'"; $result = mysql_query($q, $this->connection); return (mysql_numrows($result) > 0); Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 17, 2009 Share Posted January 17, 2009 $this-> is used to access methods and properties of current object. http://www.php.net/manual/en/language.oop5.basic.php Quote Link to comment Share on other sites More sharing options...
php_guest Posted January 18, 2009 Author Share Posted January 18, 2009 $this-> is used to access methods and properties of current object. http://www.php.net/manual/en/language.oop5.basic.php But why in the line $result = mysql_query($q, $this->connection); also $q isn't wrote in the same way as connection. Isn't also q a method? Quote Link to comment Share on other sites More sharing options...
Prismatic Posted January 18, 2009 Share Posted January 18, 2009 $this-> is used to access methods and properties of current object. http://www.php.net/manual/en/language.oop5.basic.php But why in the line $result = mysql_query($q, $this->connection); also $q isn't wrote in the same way as connection. Isn't also q a method? $q is the query <?php class MySQLDB { function usernameTaken($username){ if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "SELECT username FROM ".TBL_USERS." WHERE username = '$username'"; // <--- $q $result = mysql_query($q, $this->connection); return (mysql_numrows($result) > 0); ?> $this->connection refers to a connection variable inside the current class edit - sorry meant variable not method Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.