Query a MySQL database via a GET request

10 May 2010

Document

This PHP script serves as a bridge between a MySQL database and a client who either doesn't have the ability to speak natively to a MySQL database or by chance the database connection is too tricky to implement.

A GET request is sent this PHP script passing a MySQL query as a parameter called 'query'. This script passes the sent MySQL query on to the specified database and returns with the query results as an XML document. An XML document with an tag will be returned if the script encounters errors.

This has most recently been used to allow openFrameworks to query a local MySQL database when implementing MySQL connections natively in C++ proved to be too tricky. It may have been easier than initially thought but then otherwise I may not have made this little nugget. Further instructions are included as comments in the PHP script. Currently only SELECT statements are allowed as a security precaution but this can easily be modified within the script.

Download sql.php

Note: Please let me know if you make any updates, fixes, or changes as I welcome tinkering and would like to see what people do with this.