PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have started to create a database class to reuse in various places. I have taken what I have so far from a couple of classes found on the net. Am I going in the right direction, this only has the connec function in it so far but will eventually contain the fetch rows, last insert functions among others. Comments appreciated.
Leave out the timing though.Put more error checking aswell.
I have no idea where you get the $this->sql_time variable from. You forgot a ; on line 28.
Just a tip, your connect function is not a constructor. The constructor of a class usually has the same name as the class. Or in php5, _construct as the function name.
Otherwise, not bad as all. Try and have a look at someting like ADOdb. So that you can connect to any database and not just mysql.
Ya, get rid of the timing - that's a lot of overhead.
Returning values from your constructor is probably a personal choice, but I would either return true or false, I wouldn't return the DB link. In my opinion, objects should be encapsulated - if you want to get a value from them, write a get() method.
You're condition if (!$dbselect) could cause you some problems. You should return false if that happens. I wouldn't overwrite $this->dbLink either, though there shouldn't be a situation where you keep using the object after a db selection has failed.
Otherwise, seems pretty straightforward.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.