MyBB Community Forums

Full Version: class_datacache Bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I was writing a class for helping me in integrate MyBB with site but i found an error.

That gives me:

Fatal error: Call to a member function simple_select() on a non-object in C:\xampp\htdocs\forum\inc\class_datacache.php on line 72

code to reproduce this:
define('IN_MYBB', 1);
class MybbIntegration
{
	var $db;
	
	var $mybb;

	function __construct()
	{
		chdir("forum");
		require "global.php";
		$this->mybb = $mybb;
	}
}

$m = new MybbIntegration();

But if i do in following way it works
		chdir("forum");
		require "global.php";
		
		print_r($mybb);

I think this shouldn't happen.
The DB is global'd, so it's right.

Probably should pass a reference, not a copy, eg:
$this->mybb = &$mybb;
True, i forgot $mybb was a class object. Big Grin

But it continues to appear that error and i understand why: because $db is empty i made a var_dump and it is empty.
You need to initialise the DB then. Initialising the $mybb object doesn't load the DB. Look at inc/init.php for what MyBB loads at startup.
Yep, i know but if you notice my code i include global.php that se up everything (DB too) so theoretically init.php should be called.
Oops, I didn't see that. You need to load global.php in the global scope. You're calling it from within a function, so it'll keep the local scope of the function.
This is what i need, working it in function scope and then capture some variables and class instances of MyBB as my CMS has pluggable authentication and i have to write a class which bridges MyBB.

Before i used to work directly with MySQL Database and Cookies without using MyBB's functions but now with 1.4 that has Database Abstraction Layer, i need to use builtin functions.
MyBB explicitly calls the DB from the global scope - so if you want to use the code, you'll have to create the $db object in the global scope.
I made a bridge recently, and that's what I did.
I think i'll write my code instead of using MyBB's builtin functions althought it is the preferred way.

Thanks for your support Smile
(2008-07-04, 09:46 AM)flash.tato Wrote: [ -> ]I think i'll write my code instead of using MyBB's builtin functions althought it is the preferred way.

I promise your going to have a lot of problems supporting SQLite and PGSQL. What exactly is still your problem with the current way it works? I'm happy to make reasonable changes within MyBB before we go final to make it easier for integration.
Pages: 1 2