2025-02-06 22:43:19 +08:00

40 lines
956 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "mysql_utils.h"
/*
DBConnection *db_init(const char *host, const char *user, const char *password, const char *database, unsigned int port)
void db_close(DBConnection *db)
int db_common(DBConnection *db, const char *query)
MYSQL_RES *db_query(DBConnection *db, const char *query)
void process_result(MYSQL_RES *result)
*/
void clearUser(DBConnection *db){
db_common(db, "TRUNCATE users");
printf("Çå¿Õ³É¹¦!!! \n");
}
int addUser(DBConnection *db, char *username, char *password){
char sql[100];
sprintf(sql, "INSERT INTO users() VALUES(DEFAULT, \"%s\", \"%s\")", username, password);
printf("%s\n", sql);
return db_common(db, sql);
}
int main(void){
DBConnection *conn;
conn = db_init("localhost", "root", "root", "user", 3306);
//process_result(db_query(conn, "SELECT * FROM users"));
printf("%d\n", addUser(conn, "root", "root"));
return 0;
}