The WP Data Access API can be used to connect to local and remote databases. Here is a basic example which shows how to connect, perform a query and dump the query results on the screen.
<?php
// Connect to remote database
$wpdadb = WPDataAccess\Connection\WPDADB::get_db_connection( 'rdb:sqlserver' );
// Perform query
$rows = $wpdadb->get_results( 'select * from movies' );
// Dump query result on screen
var_dump($rows);
This code works similar for local and remote databases. A database must be accessible from WP Data Access. Access can be verified from the Data Explorer.
Notes #
- The API works similar for SQL Server, MS Access, PostgreSQL and other supported RDBMS