PHP Object Oriented aproach

Hello, could you please explain me what does the following line of code means?
I don't understand the second line of the code.

function query($query) {

$this->theQuery = $query;
return mysql_query($query, $this->link);

}
krutarth941Asked:
Who is Participating?
 
Lukasz ChmielewskiConnect With a Mentor Commented:
This function is part of the class

function query($query) {

$this->theQuery = $query;
return mysql_query($query, $this->link);

}

if you mean $this, it says, that there is also a variable
var $theQuery in the same class, passing the $query through that function as an argument sets THIS class' variable value to a given $query.
0
 
Jagadishwor DulalBraces MediaCommented:
Hi,
function query($query) is a function with a parameter $query. That means you must pass any query in the variable to run this function. your varibale $query may contain any query like. "Select * from sometable ORDER BY somefield" etc

In the second line $this->theQuery=$query passed the value to theQuery  variable for object.

In the third line return mysql_query($query, $this->link); execute the query using link which may already have defined to connect with database.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
Have a look at this tutorial, Examples

$query can be assigned to $this->theQuery  ... it can be accessed as global on the entire class.

Just look at the link
0
 
Ludwig DiehlSystems ArchitectCommented:
Line1: assigns $query to theQuery which is a class variable
Line2: returns a mysql recordset which can be fetched




0
 
krutarth941Author Commented:
It was helpful.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.