PHP Classes

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!

Moderator: General Moderators

Post Reply
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

PHP Classes

Post by AndrewBacca »

Hello,

I can using classes etc etc

but I want to know if its possible to call a class from inside a class

I'll explain why

I have a class that access a MySQL database (Item) and I have another class that does all the accessing (contect, dis-connect, etc) (db). Now I would love to bet able to us my Database (db) inside my Items (Item) classes as the db class counts queries, etc.

If this aint possible It's working as I am doing it but I thought I would ask :)

Cheers

Andrew [/b]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look down the page a tiny bit :P: viewtopic.php?t=26004
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

ahh sorry, i normally search

BUT i forgot to say they are in 2 different files can it still be done
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes.
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

anyidea how!? :P

ive tried includes an requires I just get an error
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I would bet you are missing a 'global' in your 'Item' methods..

post your code.

remove the image in your signature, it's 120K.
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

I can tell you with out posting the code that I dont have one of them, I've seen them and never un-stood the purpose

so if i was to include my db class then do

global $db;

in the constructor?
that should work
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you need global $db in every method that uses the $db object.. alternately, you'd need a local reference to $db as a class property.
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

Cheers got it :D

*sorry for the sig :)

Andrew
Post Reply