#include #include #include #include "log.h" #include "sql.h" #include "confparser.h" int add_user(void) { MYSQL *con = mysql_init(NULL); char sql[200]; if (con == NULL) { log(ERROR, "Failed to add user: %s", mysql_error(con)); return -1; } if (mysql_real_connect(con, conf_db_hostname(), "rmps", conf_db_pass(), NULL, 0, NULL, 0) == NULL) { log(ERROR, "Failed to add user: %s", mysql_error(con)); mysql_close(con); return -1; } sprintf(sql, "call addUser(`%s`, `%s`, `%s`, `%s`, `%s`, `%s`)", "user", "noob", "asd@asd.asd", "asdsadasdassda", "salt", "more"); if (mysql_query(con, sql)) { //fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } MYSQL_RES *result = mysql_store_result(con); if (result == NULL) { log(ERROR, "Failed to add user: %s", mysql_error(con)); return -1; } int num_fields = mysql_num_fields(result); MYSQL_ROW row; MYSQL_FIELD *field; while ((row = mysql_fetch_row(result))) { int i; for (i = 0; i < num_fields; i++) { if (i == 0) { while ((field = mysql_fetch_field(result))) printf("| %s ", field->name); printf("\n"); } printf("| %s ", row[i] ? row[i] : "NULL"); } } mysql_free_result(result); mysql_close(con); exit(0); }