MYSQL

Step 1: Including the MySQL Connector/C++ Header File

#include <mysql_driver.h>
#include <mysql_connection.h>

Step 2: Initializing the MySQL Connector/C++

sql::Driver *driver;
sql::Connection *con;

driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "username", "password");

Step 3: Creating a Statement Object

sql::Statement *stmt;
stmt = con->createStatement();

Step 4: Executing SQL Queries

stmt->execute("CREATE DATABASE IF NOT EXISTS testdb");
stmt->execute("USE testdb");
stmt->execute("CREATE TABLE IF NOT EXISTS testtable(id INT, name VARCHAR(50))");
stmt->execute("INSERT INTO testtable(id, name) VALUES (1, 'John')");

Step 5: Retrieving Results (if applicable)

sql::ResultSet *res;
res = stmt->executeQuery("SELECT * FROM testtable");

while (res->next()) {
  cout << "ID: " << res->getInt("id") << ", Name: " << res->getString("name") << endl;
}

Step 6: Closing the Connection and Cleaning Up

delete res;
delete stmt;
delete con;