title: using WPDB to display external database-data inside a WP-shortcode
body: <p>I'm trying to figure out a way to use WPDB to load a whole row or single cells/fields from another table (not the Wordpress-DB) and displaying them in a shortcode. I have a bunch of weatherdata-values, I need the latest row (each column is another data-type (temp, wind, humidity, etc) of the database for a start.</p>
  
  <p>Sadly, the plugin that would do everything that I need, SQL Shortcode, doesn't work anymore. I found this now:</p>
  
  <p><a href="https://de.wordpress.org/plugins/shortcode-variables/" rel="nofollow noreferrer">https://de.wordpress.org/plugins/shortcode-variables/</a></p>
  
  <p>Though I still need to use some PHP/PDO-foo to get the data from the database.</p>
  
  <p>By heavy copy&amp;pasting I came up with this:</p>
  
  <pre><code>&lt;?php
  
  $hostname='localhost';
  $username='root';
  $password='';
  $dbname='sensordata';
  
  $result = $db-&gt;prepare(SELECT * FROM `daten` WHERE id=(SELECT MAX(id) FROM `daten`););
  $result-&gt;execute();
  
  while ($row = $result-&gt;fetch(PDO::FETCH_ASSOC))
  {
  $data = $row['*'];
  }
  
  echo $data;
  
  ?&gt;
  </code></pre>
  
  <p>But obviously it's not working. What I need to get it done with WPDB?</p>
  
  <p>kind regards :)</p>