NYCPHP Meetup

NYPHP.org

[nycphp-talk] confused by classes

chris cwf at axlotl.net
Sat May 1 18:50:33 EDT 2004


The first program I wrote a couple months ago was (of course) an email program 
and now I feel it's time to try to learn the OOP aspects, so I thought I'd 
rewrite that program. After a few days, I've become utterly confused. I've 
been trying to figure out which question to ask; this one seems to capture 
several of the issues confusing me.

Each user can have several mail servers, and it seemed useful to start once a 
user logged into a session by constructing an object containing server 
addresses and passwords, and then maybe add in methods as needed. So I made 
this class (stripped down):

class mailUser{
        var $user;
function mailUser ($user){
    $dsn = 'mysql://username:pass@localhost/db';
    $dbh = DB::connect($dsn);
    $user = $dbh->quote($user);
    $this->user = $dbh->getAssoc("SELECT server, m_user, m_pass, pop, smtp, 
u.name
        FROM servers s, users u, server_pass sp
        WHERE sp.user_id = u.id
        AND sp.server_id = s.id
        AND u.username LIKE $user");
    }
}

And then when a user is logged in (returns $user ) I go:
$cur_user = new mailUser($user);

This gives me an object with an array of servers, each of those having an 
array of parameters. But I guess what I really need, maybe, is a class that 
returns 
$this->server
with a few methods (seperate queries?) to extract the parameters specific to 
the currently active server? I'm trying that now, but it's maybe my twelfth 
scheme, and it'd be nice once it fails to pan out to check this list to see 
if anyone has some pointers. 

So, I realize it's a rather broad query; anyone in a pedagogical frame of mind 
today?

Ending my lurking ways,
Chris



More information about the talk mailing list