Re: Classes Question
| From: | Gert Mellak | Date: | Tue, 21 May 2002 06:37:07 +0000 |
| Subject: | Re: Classes Question | ||
| References: | 1 | Groups: | php.lang |
| Request: | Send a blank email to php-lang+get-306@lists.php.net to get a copy of this message | ||
Paul - Zenith Tech Inc <paul@zenithtech.com> schrieb in im Newsbeitrag:
20011109162749.89874.qmail@pb1.pair.com...
> I'm hoping somebody has the answer to this!
I hope so too.
> I have 3 pages, one a normal PHP page, and 2 which are classes.
>
> One class, is a MySQL class I have written to connect/update users, etc
> And the other is the manage users on the system.
>
> Is there a way I can get the "users" class to talk to the "mysql" class?
>
> I have this code to make a new instance of the MySQL class (the True means
> use persistent connections) and a new instance of the users class
>
> $db = new MySQL(True);
> $users = new Users();
>
> I am then using this code to check the list of banned users
>
> $users->CheckBannedUser("spacetowns",$db);
>
> In the CheckBannedUser function, I have this
>
> $db->sql_query("SELECT user FROM banned_users");
>
> But that does not work, (it works fine when used from the standard PHP
page)
It doesn't work because - according to oop - every class should be
responsible for itself.
Since I don't know any possibility how objects could communicate to each
other, I'd try
the following:
simply instanciate the database-class as a class-member of the
users-class... then in the users-class
you should be able to say
$users->$db->sql_query(...)
I haven't tried that out, but IMHO it should work.
Hoping that I could help you,
greetings,
Gert.
gert@mellak.com
http://mellak.com
===================================
I'm still confused - but on a much higher level...