Running a PHP SQL script on a wordpress page

Your problem involves a technique called REST API. WordPress supports it. All you need is to make a pluginregister_rest_field → pass your data through it.

What you want to do may seems simple but it is still lot of works. Also, remember to tighten plugin security.