Advertisement
reqtrex

tt

Dec 6th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. vector<string> database::retRow(string query)
  2. {
  3.     vector<string> rRow;
  4.     MYSQL_RES *res_set; //Result set object to store output table from the query
  5.     MYSQL_ROW row; // row variable to process each row from the result set.
  6.  
  7.     bool t = mysql_query(connect, query.c_str());  // execute the query, returns Zero for success. Nonzero if an error occurred. details at https://dev.mysql.com/doc/refman/5.7/en/mysql-query.html
  8.  
  9.     if (t == false)
  10.     {
  11.         res_set = mysql_store_result(connect); //reads the entire result of a query, allocates a MYSQL_RES structure, details at: https://dev.mysql.com/doc/refman/5.7/en/mysql-store-result.html
  12.         int num_col = mysql_num_fields(res_set); // get number of columns
  13.         rRow.push_back(to_string(num_col));
  14.  
  15.         if (((row = mysql_fetch_row(res_set)) != NULL))
  16.         {
  17.             for (int i = 0; i < num_col; i++)
  18.             {
  19.                 rRow.push_back(row[i]);
  20.             }
  21.         }
  22.         return rRow;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement