This is the simply way to connect to an external database in phpBB (we go to use mysql lib here, but you could use another of these available in /phpbb32/phpbb/db/driver folder changing namespace (if on php7> you need to use mysqli and NOT mysql or you’ll get error) using phpBB db classes
$w3dbhost = 'localhost'; $w3dbuser = 'root'; $w3dbpass = 'apass'; $w3dbname = 'mydbname'; $phpbb_c = new \phpbb\db\driver\mysql(); $phpbb_c->sql_connect($w3dbhost, $w3dbuser, $w3dbpass, $w3dbname, $port = false, $persistency = false, $new_link = false); $sql = "SELECT * FROM myTable"; $result = $phpbb_c->sql_query($sql); while ($row = $phpbb_c->sql_fetchrow($result)) { print_r($row); } $phpbb_c->sql_close($result);
Note: if on Php7 > change line
$phpbb_c = new \phpbb\db\driver\mysql();
into$phpbb_c = new \phpbb\db\driver\mysqli();
to switch and use mysqli.
Comments
2 responses to “How to connect to external database using phpBB db classes”
its dos’nt work Bro
Hi there! It work fine if on phpBB32 with Php prior Php7
If on php7, may just change line
$phpbb_c = new \phpbb\db\driver\mysql();
into
$phpbb_c = new \phpbb\db\driver\mysqli();
to switch and use mysqli and … all work fine
[above edited] Cheers