4

我试图将 phpbb3 与代码点火器集成。我非常成功,但我试图访问论坛数据库并且它无法正常工作。这是目前我的数据库文件中的内容。

/** FORUM DATABASE **/

$active_group = 'forum';
$active_record = TRUE;

$db['forum']['hostname'] = 'localhost';
$db['forum']['username'] = 'root';
$db['forum']['password'] = 'root';
$db['forum']['database'] = 'phpbb';
$db['forum']['dbdriver'] = 'mysqli';
$db['forum']['dbprefix'] = 'phpbb';
$db['forum']['pconnect'] = FALSE;
$db['forum']['db_debug'] = TRUE;
$db['forum']['cache_on'] = FALSE;
$db['forum']['cachedir'] = '';
$db['forum']['char_set'] = 'utf8';
$db['forum']['dbcollat'] = 'utf8_general_ci';
$db['forum']['swap_pre'] = '';
$db['forum']['autoinit'] = TRUE;
$db['forum']['stricton'] = TRUE;

/** CMS DATABASE **/
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'cms';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = TRUE;

这是一种尝试访问数据库的方法。它一直返回null。

public function getUserGroupMembership()
{
  $forum = $this->load->database('forum',TRUE);
  global $table_prefix;
  $userId = $this->_user->data['user_id'];
  $this->forum->select('g.group_name');
  $this->forum->from($table_prefix . 'groups g');
  $this->forum->from($table_prefix . 'user_group u');
  $this->forum->where('u.user_id', $userId);
  $this->forum->where('u.group_id', 'g.group_id', FALSE);
  $query = $this->forum->get();
  foreach ($query->result_array() as $group)
  {
      $groups[] = $group['group_name'];
  }
  return $groups;
}
4

2 回答 2

1

我相信您不需要为两个数据库重新声明 $active_group 和 $active_record 。

如果您删除:

$active_group = '论坛';
$active_record = TRUE;

它可能会起作用。您还应该按照 Maxime 所说的将 $forum 更改为 $this->forum。

希望这可以帮助!

于 2013-02-04T01:38:50.723 回答
1

数据库对象加载在$forum变量中,但$this->forum变量用于与数据库交互。它不会像$forum局部变量和$this->forum类变量那样工作,它们是不一样的。要修复您的代码,您应该更改$forum$this->forum或。您不能同时使用两者。$this->forum$forum

于 2013-02-05T15:20:34.463 回答