Connecting to phpBB through Drupal

Events happening in the community are now at Drupal community events on www.drupal.org.
archard-gdo's picture

I know this module uses Drupal's database abstraction layer to get to phpBB's database. But what I don't understand is, how do the Drupal functions like db_query() and db_result() know to go into the phpBB database rather than the Drupal database? If I were to try to get some information from phpBB outside of this module, say like this:

<?php
echo db_result(db_query("SELECT post_text FROM {$phpbbcfg['db_posts']} WHERE post_id = 1"))
?>

I would get an error from Drupal saying:

user warning: Table 'drupal.drupal_phpbb_posts' doesn't exist query: SELECT post_test FROM drupal_phpbb_posts WHERE post_id = 1 in C:\xampp\htdocs\drupal\includes\database.mysql.inc on line 172.

So clearly Drupal is always adding the Drupal database prefix to the query, and this module somehow removes that prefix from the query. So my question is, how the heck does it do this?

Comments

Short answer: It doesn't,

arkepp's picture

Short answer: It doesn't, you should have them in the same database with different prefixes
http://drupal.i1media.no/drupal+phpbb/phpbb_installation

Longer answer: I know I've told people to make the prefix 'phpbb_database.phpbb_', and I think I've heard from people who use this. Whether that was all that was needed, or they added their own tweaks, I don't know. Probably isn't that hard to add a check for the syntax.

Well, that's kinda my point.

archard-gdo's picture

Well, that's kinda my point. They are in the same database with different prefixes. But this modules uses code that's exactly like what I posted above, and Drupal never has any problem with it.

Like for example, in phpbb.module you have this:

$row = db_fetch_array(db_query("SELECT * FROM {$phpbbcfg['db_config']} WHERE config_name = 'board_timezone'"));

If you were to make this same query with the part I highlighted above, anywhere else besides in this module, Drupal would not accept it because it would be looking for a table called 'drupalprefix_phpbbprefix_tablename'. The code in this module seems to be unaffected however, and I just can't figure out why.

Anyway, I've discovered that if you just leave out the curly braces around the table name, Drupal will take it as is and won't add the database prefix before it. So that does solve my problem, but I'm still quite curious why the code in this module seems to be getting special treatment from Drupal.

It works - mostly

piersg's picture

I run different databases for the forum and the drupal site. It works fine, but I had to correct phpbb.module;
Lines 136, 194 and 460 needed the backquotes (`) removed from around the database name, as follows:

Before (failed):

<?php
$sub_sql
= "INSERT INTO <code>{$phpbbcfg[&#039;db_banlist&#039;]}</code> (<code>ban_userid</code>,<code>...
?>

After (worked):
<?php
$sub_sql
= &quot;INSERT INTO {$phpbbcfg[&#039;db_banlist&#039;]} (</code>ban_userid<code>,</code>...
?>

This makes the lines consistent with the rest of the module.

Great module though, keep up the excellent work.

phpbb

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week