SHARE
TWEET

Untitled

a guest May 31st, 2017 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * MySQL++ example
  3.  *
  4.  *  Created on: Jun 14, 2010
  5.  */
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <mysql++.h>
  10.  
  11. using namespace std;
  12.  
  13. int main(int argc, char* argv[])
  14. {
  15.     int exit_code = 0;
  16.  
  17.     const char *db = NULL, *server = NULL, *user = NULL, *pass = NULL;
  18.  
  19.     db      = "mysql";
  20.     server  = "localhost";
  21.     user    = "root";
  22.     pass    = "";
  23.  
  24.     mysqlpp::Connection conn(false);
  25.  
  26.     if (conn.connect(db, server, user, pass)) {
  27.         mysqlpp::Query query = conn.query("SELECT * FROM user");
  28.  
  29.         if (mysqlpp::StoreQueryResult result = query.store()) {
  30.             for (mysqlpp::StoreQueryResult::iterator it_row = result.begin(); it_row < result.end(); it_row++) {
  31.                 for (mysqlpp::Row::iterator it_column = (*it_row).begin(); it_column < (*it_row).end(); it_column++) {
  32.                     cout << " " << *it_column;
  33.                 }
  34.  
  35.                 cout  << endl;
  36.             }
  37.         }
  38.         else {
  39.             cerr << "Failed to get item list: " << query.error() << endl;
  40.             exit_code = 1;
  41.         }
  42.     } else {
  43.         cerr << "Failed connection to database:" << endl;
  44.         cerr << setw(10) << left << "Server:" << setw(20) << server << endl;
  45.         cerr << setw(10) << left << "Database:" << setw(20) << db << endl;
  46.         cerr << setw(10) << left << "Error:" << setw(20) << conn.error() << endl;
  47.         exit_code = 2;
  48.     }
  49.  
  50.     return exit_code;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top