Re: Classes Question
[email protected] ("Gert Mellak") Tue, 21 May 2002 08:37:07 +0200
| Newsgroups | php.lang |
|---|---|
| Message-ID | <[email protected]> |
Paul - Zenith Tech Inc <[email protected]> schrieb in im Newsbeitrag: [email protected]... > 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. [email protected] http://mellak.com =================================== I'm still confused - but on a much higher level...