#include #include #include #include using namespace std; vector f; void fail(MYSQL* c) { fprintf(stderr, "%s\n", mysql_error(c)); mysql_close(c); exit(1); } int main() { MYSQL* conn = mysql_init(NULL); if (conn == NULL) { cerr << "mysql_init failed!" << endl; return 1; } if ( mysql_real_connect(conn, "localhost", "root", "datasuit86!", "homeauto", 0, NULL, 0) == NULL) { fprintf(stderr, "%s\n", mysql_error(conn)); mysql_close(conn); return 1; } if ( mysql_query(conn, "SELECT CURRENT_TIMESTAMP as 'time', version() as 'ver' UNION SELECT now(), 6543456546546456456456")) { fail(conn); } MYSQL_RES* result = mysql_store_result(conn); if (result == NULL) { fail(conn); } // int num_fields = mysql_num_fields(result); MYSQL_ROW row; while ((row = mysql_fetch_row(result))) { cout << row[0] << ", " << row[1] << endl; } mysql_free_result(result); mysql_close(conn); cout << "OK!" << endl; return 0; }