1 (edited by damaxxed 2007-05-13 18:33)

Topic: global $db doesn't work?!?


I'm trying to integrate PunBB 1.2.15 into my Wordpress blog. I successfully wrote a own login, logout and register page for the blog, but when I try to make a box in the sidebar that displays your punbb nickname and some links to the board, I always get that error:

Fatal error: Call to a member function query() on a non-object in ***\board\include\functions.php on line 129

Line 129 of my functions.php is the following: (inside the set_default_user() function)

$result = $db->query('SELECT u.*, g.*, o.logged FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Unable to fetch guest information', __FILE__, __LINE__, $db->error());

When i debug it via debug_print_backtrace() it displays:

#0 set_default_user() called at [***\board\include\functions.php:111]
#1 check_cookie(Array ()) called at [***\board\include\common.php:118]
#2 require(D:\Web\seyken\board\include\common.php) called at [***\sidebar.php:21]
... (wordpress stuff)

This means that check_cookie calls set_default_user (where the error happens) on line 111 in funtions.php..

Now back to the error itself. It should be obvious that $db causes the error, when I look what exactly $db is in that set_default_user-function (with var_dump( $db ); ) it displays:


this means that $db does not exist in that function, although it should be available because of global $db, ...

Now i want to know whether $db is available in the function that called set_default_user or not, so I add my var_dump-code to the check_cookie function and it displays (again):


Strange, isn't it? Now i wanna see whether $db is available directly before check_cookie is called (added the code to common.php before line 118 and it displays:

object(DBLayer)#32 (5) { ["prefix"]=> string(0) "" ["link_id"]=> object(mysqli)#33 (0) { } ["query_result"]=> NULL ["saved_queries"]=> array(0) { } ["num_queries"]=> int(0) }

This means that the object is available there... This is the point where I don't understand it anymore, it seems obvious that global $db doesn't work, but why?

Can anybody help me with this problem? hmm

//edit: I thought it would maybe be because of the installed CAPTCHA-addon, so I installed PunBB completely new and the same error still occurs, but not in functions.php - in include/cache.php on line 84:

$result = $db->query('SELECT * FROM '.$db->prefix.'config', true) or error('Unable to fetch forum config', __FILE__, __LINE__, $db->error());

Re: global $db doesn't work?!?


Re: global $db doesn't work?!?

This has been an issue before with Wordpress: could you paste the full code of the page where you're trying to add PunBB?