Title: Using custom mysql table inside wordpress page
Last modified: August 20, 2016

---

# Using custom mysql table inside wordpress page

 *  [bpoulsendk](https://wordpress.org/support/users/bpoulsendk/)
 * (@bpoulsendk)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/)
 * I hope this is the right forum I’m asking this ..
 * Anyway I want to add a custom page to wordpress (successful via template etc.)
 * On this page I want to display content from a mysql table that is NOT part of
   the entire wordpress family (not a wp_ table)
 * I can connect to the database and get the content I want. However all dynamic
   wordpress content in the sidebar (which comes after the mysql query I made) disappears..
   I tried NOT using the close connection call but it’s still dead.
 * Anybody have an idea what’s wrong here?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [sppadbase](https://wordpress.org/support/users/sppadbase/)
 * (@sppadbase)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481541)
 * same issue.
    I am wndering if it is due to a loss of connection to the wp database.
 *  Thread Starter [bpoulsendk](https://wordpress.org/support/users/bpoulsendk/)
 * (@bpoulsendk)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481542)
 * I don’t know what causes it, but when I just created the tables in the same database
   as wordpress itself the problem disappeared.
 *  [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * (@tugbucket)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481543)
 * You need to make a new call to wpdb:
    [http://codex.wordpress.org/Class_Reference/wpdb](http://codex.wordpress.org/Class_Reference/wpdb)
 *     ```
       <?php
       /* Config Values - You need to know these */
       $db_host = '';
       $db_user = '';
       $db_pass = '';
       $db_name = '';
   
       /* Connect to the new database */
       $externalQuery = new wpdb($db_user, $db_pass, $db_name, $db_host);
   
       /* Call WP's "get_results" on your query and create the array */
       $newQuery = $externalQuery->get_results("SELECT prodID, prodTitle, prodFormat, prodBinding FROM dvds ORDER BY prodID ASC") or die(mysql_error());
   
       //print_r($newQuery);
   
       /* Run a loop as usual on your array */
       foreach($newQuery as $q){
       	echo $q->prodTitle.'<br>';
       }
       ?>
       ```
   
 * Granted my SELECT statement uses values in my test database. You can change those
   to suit.
 *  [sppadbase](https://wordpress.org/support/users/sppadbase/)
 * (@sppadbase)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481544)
 * thanks! it works!!
 *  [tezza71](https://wordpress.org/support/users/tezza71/)
 * (@tezza71)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481546)
 * Can you include just the wpdb file from a separate standalone PHP application?
   or does it assume other vars exist?
 *  [tezza71](https://wordpress.org/support/users/tezza71/)
 * (@tezza71)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481547)
 * So far, so good. I just tried it, and it was just missing WP_DEBG so I defined
   it
 * _[65 lines of code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   The maximum number of lines of code that you can post in these forums is **ten
   lines**. Please use the [pastebin](http://wordpress.pastebin.com/)]_
 *  [tezza71](https://wordpress.org/support/users/tezza71/)
 * (@tezza71)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481548)
 * Please let me know if the above approach will have missing parts that will cause
   me problems…

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Using custom mysql table inside wordpress page’ is closed to new replies.

## Tags

 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 4 participants
 * Last reply from: [tezza71](https://wordpress.org/support/users/tezza71/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/using-custom-mysql-table-inside-wordpress-page/#post-2481548)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
