Accessing data from a non-WP database/table within a page content

<?php 
  $mydb = new wpdb('uid','passwd','database','localhost');
  $mydb->show_errors();
  $query = "SELECT DATE_FORMAT(col1, '%d-%b') AS Pdate, DATE_FORMAT(col1, '%Y') AS Pyear, col2, col3, col4, col5 AS fname FROM table ORDER BY col1 DESC LIMIT 50";
 $result = $mydb->get_results($query);
 echo $mydb->num_rows . ' in table ';
?>