Guest User

Untitled

a guest
Jun 5th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <mysql++.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. int
  10. main()
  11. {
  12. // Get database access parameters from command line
  13. const char* db = "mysql_cpp_data", *server = "localhost", *user = "root", *pass = "1234";
  14. // Connect to the sample database.
  15. mysqlpp::Connection conn(false);
  16. if (conn.connect(db, server, user, pass)) {
  17. string temp = "test1";
  18. string humi = "test2";
  19. string amps = "test3";
  20. time_t tsec = time();
  21.  
  22. string q = "INSERT INTO environmentstats (temperature, humidity, amperage, timestamp) VALUES (" + temp + ", " + humi + ", " + amps + ", " + tsec + ")";
  23.  
  24. mysqlpp::Query write_query = conn.query(q);
  25. return 0;
  26. }
  27. else {
  28. cerr << "DB connection failed: " << conn.error() << endl;
  29. return 1;
  30. }
  31. }
Add Comment
Please, Sign In to add comment