You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
practice-tracker/mysql.cpp

37 lines
880 B

#include <stdlib.h>
#include <iostream>
#include <mysql_connection.h>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>
using namespace sql;
using namespace std;
int main(void){
Driver *driver;
Connection *con;
Statement *stmt;
ResultSet *res;
driver = get_driver_instance();
con = driver->connect(getenv("DBURL"),getenv("DBUSER"),getenv("DBPWD"));
con->setSchema("timer_backend");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT seconds FROM sessions;");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("seconds") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
return 0;
}