Title: Using HyperDB/$wpdb on a server without WordPress.
Last modified: August 19, 2016

---

# Using HyperDB/$wpdb on a server without WordPress.

 *  [jlizarraga](https://wordpress.org/support/users/jlizarraga/)
 * (@jlizarraga)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/using-hyperdbwpdb-on-a-server-without-wordpress/)
 * Hi all,
 * For boring reasons that are beyond my control, I have to read from a WordPress
   database from a server that does not have WordPress installed.
 * I’ve had some limited success today using the [HyperDB class](http://codex.wordpress.org/HyperDB)
   to make this work. In short: it works, but I have to use the exact database table
   names such as “wp_posts” – ie, using “$wpdb->posts” returns nothing. I’m hoping
   you guys can help me figure out why that is, like what sort of dependencies I
   could be missing, etc.
 * Here is my test code, which outputs the currently published posts as I would 
   expect:
 *     ```
       <?php
   
       # WPDB:
   
       require_once '/XXXXX/wpdb.php';
   
       # Do some tests:
   
       $postsQuery = $wpdb->get_results("SELECT ID, post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish'");
   
       if($postsQuery){
   
       	echo '<p>Posts found:</p>'."\n";
   
       	foreach ($postsQuery as $post) {
   
       		echo '<p>#'.$post->ID.': '.$post->post_title.'<p>'."\n";
   
       	}
   
       } else {
   
       	echo '<p>No posts found.</p>'."\n";
   
       }
   
       ?>
       ```
   
 * In the code above, the “wpdb.php” file sets up the PHP constants that are normally
   defined in “wp-config.php”, and then requires the two PHP files for HyperDB.
 * The examples in the [wpdb class reference](http://codex.wordpress.org/Function_Reference/wpdb_Class)
   use “$wpdb->TABLE_NAME” in place of the actual table name in the SQL queries.
   If I change the $postsQuery line in my example code above to reflect this (using“
   $wpdb->posts” instead of “wp_posts”), the final output is instead “No posts found.”
 * Does anyone know why that might be, or what kinds of tests I could run to see
   where this is failing? Are there dependencies other than the PHP constants defined
   in “wp-config.php” that I should be including?
 * Thanks for your time. 🙂

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/using-hyperdbwpdb-on-a-server-without-wordpress/#post-1437156)
 * Look at [Integrating_WordPress_with_Your_Website](http://codex.wordpress.org/Integrating_WordPress_with_Your_Website)
 *  Thread Starter [jlizarraga](https://wordpress.org/support/users/jlizarraga/)
 * (@jlizarraga)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/using-hyperdbwpdb-on-a-server-without-wordpress/#post-1437236)
 * Thanks for the reply, but I cannot install WordPress to the server in question.

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

The topic ‘Using HyperDB/$wpdb on a server without WordPress.’ is closed to new 
replies.

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [jlizarraga](https://wordpress.org/support/users/jlizarraga/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/using-hyperdbwpdb-on-a-server-without-wordpress/#post-1437236)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
