Jump to content

this->


php_guest

Recommended Posts

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);

 

 

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.