Hello Singh_iitb,
First of all you will require a driver. You can obtain MySQL Connector for C++ from
here[
^]. The instructions for installing this connector can be found
here[
^].
The
examples
directory of the MySQL Connector for C++ contains many example program which should get you started. Below code snippet shows a small sample demonstrating how you can execute a simple SQLs.
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
stmt = con->createStatement();
stmt->execute("USE " EXAMPLE_DB);
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT, label CHAR(1))");
stmt->execute("INSERT INTO test(id, label) VALUES (1, 'a')");
delete stmt;
delete con;
Regards,