View Single Post
Old 11-27-2008, 10:56 AM   #4 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I just thought of something else, that you would take great advantage of.

When you create your user class, in your construct, or in a setdb function, set a DB variable, something like this:

PHP Code:
class user
{
private 
$db;

public function 
__construct($db)
{

if(
is_object($db)
{

$this->db $db;

}

else throw new 
exception('Database must be an object!');

}


and:

PHP Code:
$db = new yourdbclass('params');
$user = new user($db); 
I thought that this was pretty obvious, but I think that maybe someone doesn't know about it.

Anyways, what this does is that you can use the DB functions inside your user class, so whenever you query, you just do:
PHP Code:
$query $this->db->queryfunction($sql); 
Both looks good, and it's easy!
__________________
Tanax is offline  
Reply With Quote
The Following User Says Thank You to Tanax For This Useful Post:
zxt3st (11-27-2008)