MyBB Community Forums

Full Version: Same database structure but only 1 of them works
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I have a code like the following (sample.php):
///////////////////////// CONFIG START /////////////////////////
<?php
define('IN_MYBB', 1);
define('THIS_SCRIPT', 'sample.php');

require_once "./global.php";
$config['database']['type'] = 'mysqli';
$config['database']['database'] = 'db3';
$config['database']['table_prefix'] = 'mybb_';
$config['database']['hostname'] = '172.20.0.1';
$config['database']['username'] = 'mydbuserID';
$config['database']['password'] = '????';
$config['database']['encoding'] = 'utf8';
///////////////////////// CONFIG END /////////////////////////
$db->connect($config['database']);
$qry = $db->query("SELECT * FROM mybb_users WHERE uid='1'");
$result = $db->fetch_array($qry);
echo "admin : ".json_encode($result)."<br />";

This one indeed works well and return the information of admin user (uid = 1).
However, If I change db3 to db1 like the following code:

///////////////////////// CONFIG START /////////////////////////
<?php
define('IN_MYBB', 1);
define('THIS_SCRIPT', 'sample.php');

require_once "./global.php";
$config['database']['type'] = 'mysqli';
$config['database']['database'] = 'db1';
$config['database']['table_prefix'] = 'mybb_';
$config['database']['hostname'] = '172.20.0.1';
$config['database']['username'] = 'mydbuserID';
$config['database']['password'] = '????';
$config['database']['encoding'] = 'utf8';
///////////////////////// CONFIG END /////////////////////////
$db->connect($config['database']);
$qry = $db->query("SELECT * FROM mybb_users WHERE uid='1'");
$result = $db->fetch_array($qry);
echo "admin : ".json_encode($result)."<br />";

This then returns nothing. I have no idea. "db3" is the database created from the fresh copy of latest mybb version, and "db1" is the upgraded version of my old mybb forum to the latest version.

I also tested using low-level mysql api like
$fetched_array = mysqli_fetch_array($db->query("SELECT * FROM mybb_users WHERE uid='1'"), MYSQLI_ASSOC);
echo "fetched array : ".json_encode($fetched_array)."<br />";

Similarly, It works for "db3" but not "db1". It doesn't output anything for db1 but does output well for db3

Strange thing is, if i go to phpmyadmin, and run SELECT * FROM mybb_users WHERE uid='1' for "db1" database, then it works well.
[attachment=46755]

So it looks like "db1" is rejecting some query executed outside of phpmyadmin.
But i can go mybb forum utilizing db1 and all plugins works well. It just doesn't work in this way in a separate php file I create.

I don't know. Config for both db1 and db3 are exactly same, only the database name is different. PHP version used, nginx, mysqli version, mysql version all same.

What would be the cause?

I tested "fetch_field()" instead then it looks like working on db1, while "fetch_array()" works on both db1 and db3. What is the cause of this? There were multiple users in both mybb_users tables of db1 and db3 so that "fetch_array()" should have worked.