Accessing a non-wpdb database
-
I wrote a cool script (real basic) that pulls the top ten most recent posts from my phpBB forums and displays them on the front page of my WordPress site as a list of links. It works perfect if the phpBB site uses the same database as my WordPress site, which it does. Or, if I run the script stand-alone (outside of WP) from any domain on the same server. But my company also owns another forum that is on the same server but under another domain name, and when I try to pull data from that database from within WordPress, I get the error that “wordpress_db.phpbb_table does not exist” where wordpress_db is my WP database, obviously, and phpbb_table is the table I am selecting data from over at the forum, in this case phpbb_topics. I have tried the new_link idea and it does not work, I have also tried mysql_close() – any ideas? Don’t make me use an inline frame! I looked at scriptygoddesse’s site but couldn’t get that to work. To do that, where do you change the syntax of the initial WP database query? What file is it in?
Here’s my script:
<?php // Connects to the database // define ('DB_USER', 'phpbb_username'); define ('DB_PASSWORD', 'phpbb_password'); define ('DB_HOST', 'localhost'); define ('DB_NAME', 'phpbb_database_name'); $connect = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, new_link) or die(mysql_error()); $db = @mysql_select_db(DB_NAME, $connect) or die(mysql_error()); // Selects the data I want to display // $grabPosts = "SELECT topic_id, topic_title, topic_last_post_id from phpbb_topics ORDER BY topic_last_post_id DESC LIMIT 5"; $grabPosts_result= mysql_query($grabPosts) OR die('QUERY ERROR:<br />' .$grabPosts. '<br />' .mysql_error()); // Puts that data into variables for use // while ($row = mysql_fetch_array($grabPosts_result)) { $topic_id = $row["topic_id"]; $topic_title = $row["topic_title"]; $topic_last_post_id = $row["topic_last_post_id"]; // Trims long post titles down to 30 characters // $title_length = strlen($topic_title); if ($title_length > 30) { $title = substr($topic_title,0,30) . "..."; } else { $title = $topic_title; } // Displays the list of 5 links // echo "<a href=\"https://www.timbercrawler.com/bb/viewtopic.php?p=" . $topic_last_post_id . "#" . $topic_last_post_id . "\">" . $title . "</a> <br />"; } ?>
- The topic ‘Accessing a non-wpdb database’ is closed to new replies.