title: how to connect and display data from wordpress database
body: <p>UPDATED</p>
  
  <p>I tried to use this script but it doesn't appear to be working.  Could someone provide a simple working example of how to connect to a database, retrieve data and print it out?</p>
  
  <p>The script prints out Database connection working and it prints out the id but I'm not able to get the mysqli_fetch_array working and after the connection is closed doesn't print out that the database is closed</p>
  
  <pre><code>&lt;?php
  require( 'wp-load.php' );
  $local = 'xxxxxxx';
  $user  = 'xxxxxxx';
  $pass  = 'xxxxxxx';
  $data  = 'xxxxxxx';
  
  $testConnection  = mysqli_connect($local,$user,$pass, $data); 
  
  if (!$testConnection) {
  die('Error: ' . mysqli_connect_errno() . PHP_EOL);
  }
  echo 'Database connection working!';
  
  
  global $wpdb;
  $result = $wpdb-&gt;get_results ("SELECT *  FROM  $wpdb-&gt;options" );
  
  foreach ( $result as $row ){
     echo $row-&gt;option_id .'&lt;br/&gt;';       
  }
  
  $row=array();
  $row=mysqli_fetch_array($result,MYSQLI_NUM);
  print_r($row);
  
  
  // Associative array
  $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
  printf ("%s (%s)\n",$row["option_id"],$row["option_name"]);
  
  mysqli_close($testConnection);
  
   if (!$testConnection) {
      echo "database closed";
   }
  
  ?&gt;
  </code></pre>