Connecting to another server database from the wordpress plugin

I have the similar thoughts as Himad on the solution, let me elaborate.

Basically you need the following:

  1. Code an script that connects to your database directly. This is an independent script outside of the WordPress plugin. Host the script on your server. The script will take requests for data and provide response with the correct data.
  2. Code your wordpress plugin to make data requests to the API in #1 instead of directly to your database.

Given you are coding a WordPress plugin, I would assume you are familiar with PHP. So the independent script can be coded in PHP. A typical approach would be to take GET/POST requests and reply with data in JSON format. (Likely in an array / object format)

The WordPress plugin should make CURL calls to your script to make data requests, and then process the JSON response. This would replace the need to accessing the database directly. Your database credentials will be hidden as you intended.