Topic: $db object not global

It looks as though many attempts at integrating PunBB with a php script (possibly only those with) are met with this error:

Fatal error: Call to a member function on a non-object in blahblah

In every instance I've seen, the error points to a query with the $db object. Many people have stated that it appears that the $db object is not available globally, despite it being defined as global.

Some threads which addressed this problem to no avail:
http://punbb.org/forums/viewtopic.php?id=9883
http://punbb.org/forums/viewtopic.php?id=12287
http://punbb.org/forums/viewtopic.php?id=11545
http://punbb.org/forums/viewtopic.php?id=10207
(More if you search the forums for the error above)

Sorry if this has been fixed/posted before but I didn't see it anywhere.

Re: $db object not global

I don't think that could possibly be a PunBB issue, but I'd look into the issue more if someone could provide a full code example so I could replicate the issue (I don't feel like trying to install and integrate Wordpress)

Re: $db object not global

Actually, on the two occasions it happened to me, I was trying to integrate PunBB with Plogger and this poll script.

4 (edited by Smartys 2006-07-17 01:46)

Re: $db object not global

FPoll seems simple enough, I'll look into that smile
That's a poorly written script btw, it shouldn't use the <? short tag and I noticed quite a few SQL injects (assuming you don't have magic_quotes_gpc on)
How were you integrating it btw? I had no trouble adding common.php to poll.php

5 (edited by ortzinator 2006-07-17 01:48)

Re: $db object not global

It's not mine but thanks for pointing those out.

EDIT: An index.php with Connorhd's Miniportal with poll.php included into it.

Re: $db object not global

I didn't think it was your script, but since you are/were a potential user I thought I might as well point it out tongue

Re: $db object not global

To solve this problem: if you are getting this error when calling a function, make sure you put

global $db;

at the beginning of it.
Also, be sure to load common.php at the start of your script.

Re: $db object not global

This is being done! That is the whole point of this thread!

Re: $db object not global

Sorry, I was still sleepy tongue

Re: $db object not global

Has anyone been able to recreate this? It seems like a pretty widespread bug.

Re: $db object not global

I do have a theory about this: are you requiring common.php within a function?

Re: $db object not global

No, I'm not.

Re: $db object not global

Not sure if this helps, but I'm using CMS Made Simple with PunBB integrated...  and I can't run the install_mod without making changes.

In CMS Made Simple, to run install_mod, the 'db->' queries need to be 'pun_db->', and then they will run.

I thought the issue reported here might be a similar thing.