0

I'm looking for an approach in order to connect to my database from a plugin that I'm building. This plugin is going to be publicly available so the connection information would be seen by users.

Plugin needs to use data from my server's database and as it is an external database for my users wordpress websites and not in their server, I have to use something like PDO or mysqli_connect and the connecting information will be in the code which I don't want to happen.

I wonder if there is a way to connect my database without sharing my connection information in the code OR encoding that part of code or whole code without needing an extra decoder to be installed in clients server.

I have tried Ioncube encoder as well and it was pretty good but that need an extension to be installed in my clients server in order to decode and run the plugin.

It's really important for me to not share the connecting information of my database. I MUST use my database in this plugin. Thanks.

1
  • You have to set up a server as a middle man and send your requests to that server.
    – Himad
    Commented Apr 11, 2020 at 18:15

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.