{"id":2080,"date":"2017-06-02T19:53:49","date_gmt":"2017-06-02T17:53:49","guid":{"rendered":"https:\/\/www.axew3.com\/w3\/?p=2080"},"modified":"2024-06-14T19:15:42","modified_gmt":"2024-06-14T17:15:42","slug":"how-to-connect-to-external-database-using-phpbb-db-classes","status":"publish","type":"post","link":"https:\/\/www.axew3.com\/w3\/2017\/06\/how-to-connect-to-external-database-using-phpbb-db-classes\/","title":{"rendered":"How to connect to external database using phpBB db classes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This is the simply way to connect to an external database in phpBB (we go to use <strong>mysql<\/strong> lib here, but you could use another of these available in <em>\/phpbb32\/phpbb\/db\/driver<\/em> folder changing namespace (if on <strong>php7&gt;<\/strong> you need to use <em>mysqli<\/em> and NOT mysql or you&#8217;ll get error) using phpBB db classes<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$w3dbhost = 'localhost';\n$w3dbuser = 'root';\n$w3dbpass = 'apass';\n$w3dbname = 'mydbname';\n$phpbb_c = new \\phpbb\\db\\driver\\mysql();\n$phpbb_c-&gt;sql_connect($w3dbhost, $w3dbuser, $w3dbpass, $w3dbname, $port = false, $persistency = false, $new_link = false);\n$sql = \"SELECT * FROM myTable\";\n$result = $phpbb_c-&gt;sql_query($sql);\nwhile ($row = $phpbb_c-&gt;sql_fetchrow($result))\n{\n\tprint_r($row);\n}\n$phpbb_c-&gt;sql_close($result);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> if on Php7 &gt;&nbsp;<strong>change line<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$phpbb_c = new \\phpbb\\db\\driver\\mysql();<\/code><br><strong>into<\/strong><br><code>$phpbb_c = new \\phpbb\\db\\driver\\mysqli();<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">to switch and use <strong><em>mysqli.<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&gt; you need to use mysqli and NOT mysql or you&#8217;ll get error) using phpBB db classes $w3dbhost = &#8216;localhost&#8217;; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[134,131,129,130,133,132,42,128],"class_list":["post-2080","post","type-post","status-publish","format-standard","hentry","category-phpbb","tag-another","tag-connection","tag-database","tag-db","tag-different","tag-external","tag-phpbb","tag-phpbb32"],"_links":{"self":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts\/2080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/comments?post=2080"}],"version-history":[{"count":3,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts\/2080\/revisions"}],"predecessor-version":[{"id":7798,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts\/2080\/revisions\/7798"}],"wp:attachment":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/media?parent=2080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/categories?post=2080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/tags?post=2080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}