Marko Livendo
Marko Livendo

Reputation: 97

How to define this $db to my functions?

I have a problem here. I am currently making a hook, which runs a function inside a class, but it goes wrong..

It says that the variable 'db' is not defined.

Exactly error is: Notice: Undefined variable: db in /home/turborpg/public_html/script/lib/class.gamebase.php on line 72

Here is the source of the hook I run: http://pastebin.com/aKZZaafr

And here is the source for the class.gamebase.php: http://pastebin.com/fGVnY9JD

Hope someone are willing to help me out here. I am new with hooks and classes, this is my first try to make a custom one.

Upvotes: 0

Views: 78

Answers (2)

gview
gview

Reputation: 15361

Yes, you apparently are not clear on how to use class variables. Inside several of your methods you reference $db:

return $db->execute('SELECT COUNT(*) FROM `main_games` WHERE `url`=?', array($this->getSubdomain()));

This needs to be:

return $this->db->execute('.....');

Make sure that anyplace you are using the protected $db variable in your class, you reference it properly.

Upvotes: 1

pozs
pozs

Reputation: 36214

You use $db as a variable in your method. You should use it as a property $this->db.

Upvotes: 2

Related Questions