This project consists of two components: a C++ tool (SQL-Tool) and a PHP script (sql.php). Together, they work to send MySQL queries from the C++ application to the PHP server, which processes the queries and returns the results. It's a lightweight and efficient way to interact with a MySQL database using a combination of C++ and PHP
- SQL-Tool (C++): A command-line tool written in C++ that sends SQL queries to a web server.
- PHP Script (sql.php): A backend PHP file that receives the query, executes it on a MySQL database, and returns the result.
This setup allows for the execution of MySQL queries remotely, providing a way to interact with databases in a cross-platform environment using HTTP requests.
- Send SQL Queries from C++: Use the SQL-Tool to send any MySQL query to the PHP server. The data from the MySQL database is stored in a PHP file, which ensures that the data will not be exposed.
├── sql-tool.cpp # The C++ source file for SQL-Tool
├── sql.php # The PHP file that handles MySQL queries
└── README.md # Project documentation
-
SQL-Tool (C++):
- Sends an HTTP request with the SQL query to the server where
sql.php
is hosted. - Receives the result of the query from the server.
- Sends an HTTP request with the SQL query to the server where
-
PHP Script (sql.php):
- Receives the SQL query via an HTTP request from the C++ application.
- Executes the query on a MySQL database.
- Sends the results back to the C++ application as a response.
-
C++ Tool (SQL-Tool) sends the following SQL query:
SELECT * FROM users WHERE id = 1;
-
PHP Script (sql.php) processes the request, runs the query on the MySQL server, and returns the result:
{ "id": 1, "name": "John Doe", "email": "john.doe@example.com" }
-
Make sure you have a working C++ compiler (e.g.,
g++
orclang++
). -
Compile the
sql-tool.cpp
file:g++ -o sql-tool sql-tool.cpp
-
Run the tool:
./sql-tool
- Place
sql.php
on your web server. - Ensure you have a MySQL server running and properly configured.
- Modify
sql.php
to include your MySQL database credentials.
$servername = "host";
$username = "username";
$password = "password";
$dbname = "database";
-
SQL-Tool: Send a query from the C++ application. The SQL query is passed as a string argument, converted to Base64 format, and then sent via HTTP to the server hosting
sql.php
.// Example: Sending a SQL query SQL sql; // Create an instance of the SQL class to work with queries std::string request = "SELECT * FROM users WHERE 1;"; // Define the SQL query as a string std::string response = sql.SendRequest(request); // Send the request to the server and receive the response
-
PHP Script:
sql.php
receives the query, executes it, and returns the result.
- C++ Compiler: g++, clang++, or any C++ compiler.
- PHP: PHP 7.0+ with MySQLi extension.
- MySQL: A MySQL server to execute the queries.
- Web Server: Apache or any server capable of running PHP scripts.
This project is licensed under the MIT License. See the LICENSE file for more details.
May the force be with You!