How to use connector of mysql
Question
I want to use connector for mysql data base. I am follow this page
http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html
But it seems hard . Is there any other tutorial present. Please let me know.
Solution
the relevant part of the example code is pretty simple:
Driver *driver;
Connection *con;
Statement *stmt;
ResultSet *res;
driver = get_driver_instance();
/* create a database connection using the Driver */
con = driver -> connect(url, user, password);
/* alternate syntax using auto_ptr to create the db connection */
//auto_ptr con (driver -> connect(url, user, password));
/* turn off the autocommit */
con -> setAutoCommit(0);
/* select appropriate database schema */
con -> setSchema(database);
From there on you just have to query it like so:
stmt = con -> createStatement();
res = stmt -> executeQuery ("SELECT * FROM City");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow