Tell me why when you try to use the function, the Error goes out: can't execute INSERT-query? What is wrong with the request?
Table structure
1 id int(11) 2 time datetime 3 rad int(11) 4 temp float 5 hum float 6 pres int(6) Code
void insertToDb(short int r, float t, float h, short int p) { MYSQL conn; if(!mysql_init(&conn)) { fprintf(stderr, "Error: can't create MySQL-descriptor\n"); exit(1); } if(!mysql_real_connect(&conn, "localhost", "user", "xxxxx", "my_db", 0, NULL, 0)) { fprintf(stderr, "Error: %s\n", mysql_error(&conn)); exit(1); } if(mysql_query(&conn, "SET NAMES 'utf8' COLLATE 'utf8_general_ci'") != 0) { fprintf(stderr, "Error: can't set character set\n"); exit(1); } char query[400]; sprintf(query, "INSERT INTO my_table(rad, temp, hum, pres) VALUES (%i, %f, %f, %i)", r, t, h, p); if(mysql_query(&conn,query) !=0); { fprintf(stderr, "Error: can't execute INSERT-query\n"); exit(1); } mysql_close(&conn); }