3) We only use var for PHP4. Once you get into PHP5, you'll want to use the public, provate, and protected keywords.
and exceptions and abstracts and interfaces and occasionally statics and overloading.
Code: Select all
return new db_result($this->link_id, mysql_query($sql, $this->link_id));
You'll probably want to check for query success first. If it fails trigger and error and result false. You don't want to return a result object with an invalid state.
1: Should this be split into two files? ie: db_connect.class.php & db_result.class.php
I would say so.
3: Can someone reference me an article about private, public, protected, etc keywords before the functions and properties? I'm almost pretty sure that "var" shouldn't be used?
Public -> accessible to all.
Protected -> accessible to self and subclasses.
Private -> accessible to self only.
These 3 keywords (there's a forth in Java) define the visibility of the class and allow you to achieve encapsulation. When I was learning C++ this was known as data hiding as well. The purpose of this is pretty much the same as function scope. You don't want to allow class internals to be fiddled with from the outside.
You should know by now there are usually no hard rules; everyone has their own opinion on everything; a lot of things have to be assessed on a case by case basis. Public properties are one of the few exceptions to this. Public properties are bad. If you never make a property public you'll be fine. Protected and private are different. I prefer to make everything non-public private and make them protected if it turns out I need them further down the inheritance chain. Others almost never use private at all, you only very occasionally
need private - singletons are a good example of this.