Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. char buf[LEN];
  2. time_t curtime;
  3. struct tm *loc_time;
  4.  
  5. curtime = time (NULL);
  6.  
  7. loc_time = localtime (&curtime);
  8.  
  9.  
  10. strftime (buf, LEN, "%Y-%m-%d" " " "%X", loc_time);
  11. fputs (buf, stdout);
  12.  
  13.  
  14. MYSQL *con = mysql_init(NULL);
  15.  
  16. if (con == NULL)
  17. {
  18. fprintf(stderr, "mysql_init() failedn");
  19. exit(1);
  20. }
  21.  
  22. if (mysql_real_connect(con, "localhost", "user", "pass", "TempDB", 0, NULL, 0) == NULL)
  23. {
  24. finish_with_error(con);
  25. }
  26.  
  27. if (mysql_query(con, "CREATE TABLE IF NOT EXISTS TempMeas(MeasTime DATETIME, Temp DOUBLE)"))
  28. {
  29. finish_with_error(con);
  30. }
  31.  
  32. if (mysql_query(con, "INSERT INTO TempMeas(MeasTime, Temp) VALUES('%d', '%d')", buf, j))
  33. {
  34. finish_with_error(con);
  35. }
  36.  
  37. mysql_close(con);
  38.  
  39. exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement