Query from a different database than the default

I don’t know why the mysql_connect isn’t working inside WordPress. But an easier way of doing it would be to use the $wpdb class. Try replacing your code with this:

$second_db = new $wpdb( 'user', 'pass', 'dbname', 'host' );
$q = $second_db->get_results( 'SELECT * FROM vars' );
var_dump( $q );

and see if you get the results you want. (note that the order of the variables passed to the $wpdb constructor is different from the order used by mysql_connect)