I am trying to pull some data from a remote wordpress database. Here is the code I have:

    $server = "my server code";
    $user = "my username";
    $password = "my password";
    $db = "mydb";
    $con = mysql_connect($server,$user,$password); 
    if (!$con) {
        die("database connection error");
    
    } else {
    
    mysql_select_db($db, $con);
    
    function dp_get_user_liked_posts($user_id, $fields = '') {
    
    	global $wpdb;
    
    	$tempDB = $wpdb;
    
    $wpdb = new wpdb($user, $password, $db, $server);
    
    	// Get user settings
    	$settings = get_option('dp_post_likes');
    
    		$login_required = !empty($settings['login_required']) ? true : false;
    
    			if($login_required && !is_user_logged_in()) {
    
    				echo '<p class="must-login">'.sprintf(__('You must <a href="%1$s">register</a> and <a href="%2$s">login</a> to view your liked videos.', 'dp'),  site_url('wp-login.php?action=register', 'login'), wp_login_url()).'</p>';
    
    			} else {
    
    	$settings = get_option('dp_post_likes');
    	$user = get_current_user_id();
    	$user_id = 2;
    	$likes=query_posts(array(
    							'post_type' => 'post',
    							'ignore_sticky_posts' => true,
    							'filter_type' => 'user_liked',
    							'filter_user' => $user_id
    						));
    					
    				global $wp_query;
                     $likes= array();
    				 while (have_posts()) : 
    							$likes[]=the_post()	;
    						endwhile;
    							
    }}}  
    		mysql_close($con);
    
    $wpdb = $tempDB;


but it is not display `$likes`. What is did wrong?