MyBB Community Forums

Full Version: What is $db?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I downloaded a plugin and I searched everywhere but it immediately started using
$db

I don't see how it was declared anywhere?

I'm running into a SQL error so I'm wondering if it's using MySQL instead of PostgreSQL which is what I installed

... I've never used PHP before I'm just confused how none of the files declared $db but started using it right away

edit:
So I changed a setting in myBB and this is more detail for the error:
0 - ERROR: syntax error at or near "`" LINE 1: CREATE TABLE `mybb_newpoints_settings` ( ^
CREATE TABLE `mybb_newpoints_settings` ( `sid` int(10) UNSIGNED NOT NULL auto_increment, `plugin` varchar(100) NOT NULL default '', `name` varchar(100) NOT NULL default '', `title` varchar(100) NOT NULL default '', `description` text NOT NULL, `type` text NOT NULL, `value` text NOT NULL, `disporder` smallint(5) UNSIGNED NOT NULL default '0', PRIMARY KEY (`sid`) ) ENGINE=MyISAM

edit: how come it's using backticks ` instead of quotes ' or " ?

edit: ok it looks like MySQL uses backticks, and that's not a thing in PostgreSQL?
$db is a variable that is defined in MyBB's initialization files and is available across every file in MyBB. You won't see it initialized in the plugin file itself because it is initialized in a globally included file, along with $mybb, $input, etc. All of these are available across all of MyBB.

However, just a quick look at this query and it is requesting the MyISAM engine, which is not present (IIRC) in PostgreSQL. This alone is a pretty clear indication that this plugin does not appear to support PostgreSQL, and if this query were to be fixed, others would likely be broken as well.

I will leave PostgreSQL related questions to other PostgreSQL users (who will know much more on this topic than I will), but if you don't mind me asking, what host are you using? Curious as to whether or not MySQL/MariaDB might be a better solution for you (depending on your needs specifically)?

PostgreSQL has its advtantages for some use cases, but it might not be the best option for optimal compatibility with the largest number of plugins. MyBB itself suports PostgreSQL fully, but plugins don't necessarily guarantee the same level of support. It largely depends on your needs specifically, and other PostgreSQL users may be able to answer this better than I can. Smile
Thanks for the explanation about $db and other parts of myBB... I need to modify some things some things to fit with my main website so that should make it a little easier to figure out...

I chose PostgreSql cause I wasn't sure, I'm still on my localhost I only got it installed yesterday so it seems obvious and won't be a problem for me just to use MySQL..
Ahh, I see. Yea I would consider going with MySQL at this point. It is the most popular choice for most forums on the internet (including MyBB), so it's just as robust as any other option available. It will solve a number of compatibility issues with various plugins and otherwise. Smile

Let us know if you have any other questions!
(2020-09-29, 06:43 AM)Darth Apple Wrote: [ -> ]Ahh, I see. Yea I would consider going with MySQL at this point. It is the most popular choice for most forums on the internet (including MyBB), so it's just as robust as any other option available. It will solve a number of compatibility issues with various plugins and otherwise. Smile

Let us know if you have any other questions!

ok thank you Smile yea im going with MySQL lols
(2020-09-29, 01:34 AM)Darth Apple Wrote: [ -> ]$db is a variable that is defined in MyBB's initialization files and is available across every file in MyBB. You won't see it initialized in the plugin file itself because it is initialized in a globally included file, along with $mybb, $input, etc. All of these are available across all of MyBB.

Can u help me figure out where $mybb comes from in member.php? It shows up on line ~39

I made a new .php file that I'm using as an API, and I'm sending requests to it from my server as regular GET .com/myfile.php with only one header in the request: Cookie: <uid>_<loginkey>

But in the .php file I don't have access to $mybb.... Can u help me figure out why? plzz hehe

I added all this to the .php file (taken straight from member.php, but I'm not getting the $mybb variable:
define("IN_MYBB", 1);
define("IGNORE_CLEAN_VARS", "sid");
define('THIS_SCRIPT', 'member.php');
define("ALLOWABLE_PAGE", "register,do_register,login,do_login,logout,lostpw,do_lostpw,activate,resendactivation,do_resendactivation,resetpassword,viewnotes");
require_once "./global.php";

//require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";

I'm getting the cookie from this code I hacked together from member.php:
require_once MYBB_ROOT."inc/datahandlers/login.php";

$user = array(
	'username' => $alias//,
	//'password' => '',
	//'remember' => '',
	//'imagestring' => ''
);

$loginhandler = new LoginDataHandler("get");

$loginhandler->set_data($user); // 3 lines of code
$validated = $loginhandler->validate_login();
$loginhandler->complete_login();
When my server calls that code, it sends back a cookie with a bunch of values... I ignore the sid and take the mybbuser value.... then I store it in my browser as a cookie "mybbuser=<uid>_<loginkey>" and when I switch over to the forum, I automatically become logged in

So I think the Cookie part should work on this .php file and give me $mybb... but I don't have it
Hmm maybe the difference is that the cookie sent by the browser...

...is being interpreted but the cookie sent by the server isn't being interpreted/read?