4

Im trying to intergrate phpbb3 with code igniter. im pretty successful but im tryying to access the forum database and it not working. This is currently what I have in my database file.

/** 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;

And here is a method that is trying to access the database. It keeps returning 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;
}
3
  • 3
    Did you try to replace $forum by $this->forum on the first line of the method? $forum and $this->forum is not the same thing. Commented Feb 3, 2013 at 18:42
  • IF this was this was an answer i would be able to give it the check mark. Commented Feb 5, 2013 at 14:32
  • I've added my answer with a bit more meat to it. :) Commented Feb 5, 2013 at 15:21

2 Answers 2

1

The database object is loaded in the $forum variable, but the $this->forum variable is used to interact with the database. It's not going to work as $forum is a local variable and $this->forum is an class variable, they aren't the same. To fix your code, you should change $forum to $this->forum or $this->forum to $forum. You can not use both at the same time.

Sign up to request clarification or add additional context in comments.

Comments

1

I believe you do not need to redeclare $active_group and $active_record for both databases.

If you remove:

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

It might work. You should also do what Maxime said and change $forum with $this->forum.

Hope this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.