The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

My first real attempt with OOP.

Morning peeps,

I was wondering if people could advise of better ways to do what i've attempted to.

Its just a small class to carry out a select query, as i'm learning i guess i need critism for me to learn from my mistakes so fire away. Ignore how i have displayed the data as thats not what im intrested in, that was just to show it worked.
Beleive me, its nothing fancy!

Class:

Code PHP:

<?phpclass select {var$query;// will store the query string only.var$result;// will store the results after the execute function is called.function __construct($columns,$table,$clause){// Create the query and store in var "query"$query="SELECT ";$query.=implode(", ",$columns);// separate the colums.$query.=" FROM ".$table;$query.=$clause;$this->query=$query;}function execute (){//execute the query and store the results into the var "results";$this->result=mysql_query($this->query);}}?>

I would recommend using 'protected' keyword instead of 'var'
and definetely dont make the $result public. You should either make it protected and have accessor method OR just have your execute method return the result.

oh i know i know, i wont be using this code this is just me making up more or less, pointless and useless classes just as a challenge for me. I just want to know if my coding techniques are terrible and need improving etc.

Well properties should always be protected or private. Properties should only be accessible to the outside world indirectly through getter and setters. Furthermore, if a method only needs to be accessed from within the scope of the object then you should consider having those be protected or private also. Limiting the methods which are accessible outside the scope of the object leads to a simplified public interface. The simpler the public interface the easier the class is to use and understand months or years down the line.