Oops..
This commit is contained in:
55
sql.c
Normal file
55
sql.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <mysql.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "log.h"
|
||||
#include "sql.h"
|
||||
#include "confparser.h"
|
||||
|
||||
int add_user()
|
||||
{
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user