I need to connect my wordpress site to another database that is stored on a VPS, I also want to use this connection to query data and show it on my wordpress site, I see that I can connect to the database using this code on the functions.php file :
function seconddb() {
global $seconddb;
$seconddb = new
wpdb('Username','password','database name','localhost');
}
add_action('init','seconddb');
but how can I use this on the site? Can i create another php file anywhere and whenever I need to for example query data I can make a trigger from a button and query the data?:
for example something like this:
global $seconddb;
$user_count = $seconddb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
echo "<p>User count is {$user_count}</p>";
well I could do a request and return the data but is just a example, also if this is a vps do i need to connect in another way? thanks