Title: Show data from external database
Last modified: October 8, 2020

---

# Show data from external database

 *  [m3nister](https://wordpress.org/support/users/m3nister/)
 * (@m3nister)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/show-data-from-external-database/)
 * Hello,
 * I’m currently trying to show data from an external database on my wordpress website.
   I’m not really new to wordpress but this kind of topic is brand new to me, so
   I’m a little bit lost here.
 * So I have a database called “persons” with a table “stats_persons” and I want
   to grab the “lastconnection” ([https://i.imgur.com/FJcGRQR.png](https://i.imgur.com/FJcGRQR.png))
   which basically contains the data when the person was last online.
 * I have created a child theme and within the functions.php it currently looks 
   like this:
 * $wpdb_b = new wpdb(DB_USER, DB_PASS, ‘stats_persons’, ‘external_ip’);
    $wpdb_b-
   >get_results( “SELECT * FROM stats_persons” );
 * What would I need to do in order to show “lastconnection” data?
 * Thank you very much!

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/show-data-from-external-database/#post-13514566)
 * Place your code in a function declaration so it does not execute until it’s called.
   Better yet, make it into a shortcode handler so it can be called from page content.
   
   [https://developer.wordpress.org/plugins/shortcodes/](https://developer.wordpress.org/plugins/shortcodes/)
 * How you display the results depends upon the nature of table structure. To get
   an idea of what sort of data you are getting back, you could do:
    `return print_r(
   $wpdb_b->get_results('SELECT * FROM stats_persons'), true );` as the final line
   in your shortcode handler function declaration.

Viewing 1 replies (of 1 total)

The topic ‘Show data from external database’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [external data](https://wordpress.org/support/topic-tag/external-data/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [5 years, 7 months ago](https://wordpress.org/support/topic/show-data-from-external-database/#post-13514566)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
